У меня возникает следующая проблема: я использую следующий код для чтения всех файлов из папки. Метод TrainAugmentGenerator () должен дать мне 5 изображений и соответствующие 5 файлов меток. К сожалению, если я печатаю фотографии / этикетки, они никогда не совпадают. Я не могу распознать проблему. Помещение семени не помогает, равно как и установка 'shuffle = False'.
Вывод, который я получаю из следующего кода:
#
'''
seed=1
def TrainAugmentGenerator(batch_size = 5):
'''Train Image data generator
Inputs:
seed - seed provided to the flow_from_directory function to ensure aligned data flow
batch_size - number of images to import at a time
Output: Decoded RGB image (height x width x 3)
train_image_generator = train_frames_datagen.flow_from_directory(
DATA_PATH + 'train_frames',
batch_size = batch_size, shuffle=False,seed=1)
train_mask_generator = train_masks_datagen.flow_from_directory(
DATA_PATH + 'train_masks',
batch_size = batch_size,shuffle=False,seed=1)
while True:
X1i = train_image_generator.next()
X2i = train_mask_generator.next()
#One hot encoding RGB images
mask_encoded = [rgb_to_onehot(X2i[0][x,:,:,:], id2code) for x in range(X2i[0].shape[0])]
yield X1i[0], np.asarray(mask_encoded)
def ValAugmentGenerator(batch_size = 5):
'''Validation Image data generator
Inputs:
seed - seed provided to the flow_from_directory function to ensure aligned data flow
batch_size - number of images to import at a time
Output: Decoded RGB image (height x width x 3)
'''
val_image_generator = train_frames_datagen.flow_from_directory(
DATA_PATH + 'val_frames/',
batch_size = batch_size, seed = seed)
val_mask_generator = train_masks_datagen.flow_from_directory(
DATA_PATH + 'val_masks/',
batch_size = batch_size, seed = seed)
while True:
X1i = val_image_generator.next()
X2i = val_mask_generator.next()
#One hot encoding RGB images
mask_encoded = [rgb_to_onehot(X2i[0][x,:,:,:], id2code) for x in range(X2i[0].shape[0])]
yield X1i[0], np.asarray(mask_encoded)
training_gen = TrainAugmentGenerator()
testing_gen = ValAugmentGenerator()
batch_img,batch_mask = next(training_gen)
print("batch_img.shape(): ", shape(batch_img))
print("batch_mask.shape(): ", shape(batch_mask))
#print("testing_gen", training_gen)
pred_all= model.predict(batch_img)
np.shape(pred_all)
for i in range(0,np.shape(pred_all)[0]):
fig = plt.figure(figsize=(20,8))
ax1 = fig.add_subplot(1,3,1)
ax1.imshow(batch_img[i])
ax1.title.set_text('Actual frame')
ax1.grid(b=None)
ax2 = fig.add_subplot(1,3,2)
ax2.set_title('Ground truth labels')
ax2.imshow(onehot_to_rgb(batch_mask[i],id2code))
ax2.grid(b=None)
ax3 = fig.add_subplot(1,3,3)
ax3.set_title('Predicted labels')
ax3.imshow(onehot_to_rgb(pred_all[i],id2code))
ax3.grid(b=None)
[enter image description here][1]# plt.savefig('/net/store/nbp/projects/affordance_prediction/alimberg/affordancemaps_unet/results/02_CamVid_Semantic _Segmentation/Results_Semantic_Segmentation_01.png')
plt.show()