I am trying to save the name of objects as image in specific order. Like if there are seven objects detected in image and their names are [chair, tv, bed, chair ,bed, chair, chair]. I want that it should be saved as [chair.png, chair1.png, chair2.png, chair3.png, bed.png, bed1.png, tv.png]. No matter what objects comes first but its numbers should remains in sequential order respectively. I am trying but is it giving me results like: [bed.png, bed2.png, chair.png, chair1.png, chair3.png, chair4.png, tv.png] . I guess i have not setted the count variable correctly but I am unable to find it out
My code:
%cd /content/drive/MyDrive/Now_fine/yolov7-mask/binary_masks_images
folder_name = 'my_folder_' + time.strftime("%Y_%m_%d_%H_%M_%S")
os.mkdir(folder_name)
count = 0
for one_mask, bbox, cls, conf in zip(pred_masks_np, nbboxes, pred_cls, pred_conf):
if conf < 0.25:
continue
else:
label = names[int(cls)]
print(label)
if os.path.exists('/content/drive/MyDrive/Now_fine/yolov7-mask/binary_masks_images/'+folder_name+'/'+label+'.png'):
count+=1
plt.imsave('/content/drive/MyDrive/Now_fine/yolov7-mask/binary_masks_images/'+folder_name+'/'+label+str(count)+'.png', one_mask, cmap='gray')
else:
plt.imsave('/content/drive/MyDrive/Now_fine/yolov7-mask/binary_masks_images/'+folder_name+'/'+label+'.png', one_mask, cmap='gray')