0

I have a number of images and a list of ids associated with each of those images. For the time being I am storing all the images in a list. For e.g.

image_list = [image1, image2, image3, image4, image5, ...]
ids = [1, 2, 1, 1, 1, ...]
  1. I want to pass these images in a batch(of any size) to an Image Classification Algorithm and based on the results of the algorithm I want to change the ids in the list.
  2. I do not want to pass all the images in the list to the algorithm and want to pass images having only specific ids to the algorithm. For e.g. images with id value 1 should be pass to algorithm or images with id value 2 should be passed to the algorithm. Till now I have written the algorithm which looks something like the following.
image_list = [image1, image2, image3, image4, image5]
ids = [1, 2, 1, 1, 3]

for idx in range(0, len(image_list), batch_size):
    image_batch = image_list[idx, idx+batch_size]
    result = model.predict(image_batch)         # model is the Image classification algorithm
    ids[idx:idx+4][result > 0.5] = new_id       # new_id can be any new id value which is not present in the ids list

The above code runs the algorithm on batches of 4 but runs it on all the images instead of images belonging to a specific id(s) which can unwantedly alter the ids which I do not want to be changed. Also I tried doing something like

r['class_ids'][idx:idx+batch_size][result > 0.5 and (r['class_ids'][idx:idx+16] == 2)] = new_id

but it gives an error in the second and condition.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Ahmad Javed
  • 544
  • 6
  • 26

0 Answers0