问题描述
def generate_image_folder_structure(frames,masks,frames_list,masks_list):
'''Function to save images in the appropriate folder directories
Inputs:
frames - frame tensor dataset
masks - mask tensor dataset
frames_list - frame file paths
masks_list - mask file paths
'''
#Create iterators for frames and masks
frame_batches = tf.compat.v1.data.make_one_shot_iterator(frames) # outside of TF Eager,we would use make_one_shot_iterator
mask_batches = tf.compat.v1.data.make_one_shot_iterator(masks)
#Iterate over the train images while saving the frames and masks in appropriate folders
dir_name='train'
for file in zip(frames_list[:-round(0.2*len(frames_list))],masks_list[:-round(0.2*len(masks_list))]):
#Convert tensors to numpy arrays # khawar
frame = frame_batches.next(g).numpy().astype(np.uint8)
mask = mask_batches.next(g).numpy().astype(np.uint8)
#Convert numpy arrays to images
frame = Image.fromarray(frame)
mask = Image.fromarray(mask)
#Save frames and masks to correct directories
frame.save(DATA_PATH+'{}_frames/{}'.format(dir_name,dir_name)+'/'+file[0])
mask.save(DATA_PATH+'{}_masks/{}'.format(dir_name,dir_name)+'/'+file[1])
#Iterate over the val images while saving the frames and masks in appropriate folders
dir_name='val'
for file in zip(frames_list[-round(0.2*len(frames_list)):],masks_list[-round(0.2*len(masks_list)):]):
#Convert tensors to numpy arrays
frame = frame_batches.next().numpy().astype(np.uint8)
mask = mask_batches.next().numpy().astype(np.uint8)
#Convert numpy arrays to images
frame = Image.fromarray(frame)
mask = Image.fromarray(mask)
#Save frames and masks to correct directories
frame.save(DATA_PATH+'{}_frames/{}'.format(dir_name,dir_name)+'/'+file[1])
print("Saved {} frames to directory {}".format(len(frames_list),DATA_PATH))
print("Saved {} masks to directory {}".format(len(masks_list),DATA_PATH))
generate_image_folder_structure(frame_tensors,masks_tensors,masks_list)
#generate_image_folder_structure(train_frames,train_masks,val_files,'val')
TypeError Traceback (most recent call last)
/home/khawar/.local/lib/python2.7/site-packages/tensorflow/python/keras/api/_v1/keras/models/__init__.pyc in <module>()
48 print("Saved {} masks to directory {}".format(len(masks_list),DATA_PATH))
49
---> 50 generate_image_folder_structure(frame_tensors,masks_list)
51
52 #generate_image_folder_structure(train_frames,'val')
/home/khawar/.local/lib/python2.7/site-packages/tensorflow/python/keras/api/_v1/keras/models/__init__.pyc in generate_image_folder_structure(frames,masks_list)
13 #Iterate over the train images while saving the frames and masks in appropriate folders
14 dir_name='train'
---> 15 for file in zip(frames_list[:-round(0.2*len(frames_list))],masks_list[:-round(0.2*len(masks_list))]):
16
17
TypeError: slice indices must be integers or None or have an __index__ method
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)