Skip to content
Snippets Groups Projects
Commit 71d61f38 authored by tgupta6's avatar tgupta6
Browse files

code to get a batch of shape images as 4D ndarray

parent 7bc48664
No related branches found
No related tags found
No related merge requests found
......@@ -6,19 +6,19 @@ import matplotlib.image as mpimg
import numpy as np
def obj_mini_batch_loader(json_filename, start_index, batch_size, im):
def obj_mini_batch_loader(json_filename, start_index, batch_size, img_height=100, img_width=100, channels=3):
with open(json_filename, 'r') as json_file:
json_data = json.load(json_file)
obj_images = np.empty(shape=[9*batch_size, ])
obj_labels = []
obj_images = np.empty(shape=[9*batch_size, img_height, img_width, channels])
obj_labels = np.empty(shape=[9*batch_size])
for i in range(start_index, start_index + batch_size):
image_name = os.path.join(image_dir, str(i+1) + '.jpg')
image = mpimg.imread(image_name)
crop_shape = [image.shape[0]/3, image.shape[1]/3]
selected_anno = [q for q in json_data if q['image_id']==1]
crop_shape = np.array([image.shape[0], image.shape[1]])/3
selected_anno = [q for q in json_data if q['image_id']==i+1]
grid_config = selected_anno[0]['config']
counter = 0;
......@@ -27,14 +27,15 @@ def obj_mini_batch_loader(json_filename, start_index, batch_size, im):
start_row = grid_row*crop_shape[0]
start_col = grid_col*crop_shape[1]
print([start_row, start_col])
obj_images.append(image[start_row:start_row+crop_shape[0]-1, start_col:start_col+crop_shape[1]-1, :])
obj_labels.append(grid_config[6*grid_row+2*grid_col])
# imgplot = plt.imshow(obj_images[counter])
# plt.show()
cropped_image = image[start_row:start_row+crop_shape[0], start_col:start_col+crop_shape[1], :]
obj_images[9*(i-start_index)+counter,:,:,:] = cropped_image
obj_labels[9*(i-start_index)+counter] = grid_config[6*grid_row+2*grid_col]
counter = counter + 1
# imgplot = plt.imshow(obj_images[0,:,:,:].astype(np.uint8))
# plt.show()
if __name__=="__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment