سلام. به دلیل حجیم بودن دیتاستم از generator ها دارم استفاده می کنم و چون به برچسب کل دیتاستم نیاز دارم خودم دیتاستم رو بر اساس نام تصویر و برچسب مرتب کردم و دارم از flow_from_dataframe استفاده می کنم.. در بخش dataframe من همون فایل train_df که به صورت csv. ذخیره کردم رو میدم که به صورت زیر است:
train_df
Unnamed: 0 FileName Label ClassName
0 0 augment_0_5974.png 0 detained
1 1 augment_0_2150.png 0 detained
2 2 augment_0_1570.png 0 detained
3 3 augment_0_8006.png 0 detained
4 4 augment_0_868.png 0 detained
... ... ... ... ...
46956 46956 augment_1_1733.png 1175 doorman
46957 46957 augment_1_7330.png 1175 doorman
46958 46958 augment_1_5509.png 1175 doorman
46959 46959 augment_1_4611.png 1175 doorman
46960 46960 augment_1_7049.png 1175 doorman
[46961 rows x 4 columns]
و قسمت کدی که مربوط به generator هست به صورت زیر است:
train_datagen = ImageDataGenerator(rescale=1./255)#, validation_split=0.3)
val_datagen = ImageDataGenerator(rescale=1./255)
# custom generator
def multiple_outputs(generator, image_dir, dataframe,directory, x_col, y_col, image_sizeW, image_sizeH, batch_size, subset):
gen = generator.flow_from_dataframe(
image_dir,
dataframe,
directory,
x_col,
y_col,
batch_size=batch_size,
target_size=(image_sizeW, image_sizeH),
color_mode = 'grayscale',
class_mode='sparse',
shuffle=True,
subset=subset)
while True:
gnext = gen.next()
# return image batch and 3 sets of lables
yield gnext[0], [gnext[1], gnext[1]]
# train_generator = train_datagen.flow_from_directory(
# train_folder, batch_size=128, class_mode="categorical")
train_generator = multiple_outputs(
train_datagen,
image_dir=train_folder,
dataframe = train_df,
directory = None,
x_col='FileName',
y_col='Label',
image_sizeW=48, image_sizeH=128,
batch_size=batch_size,
subset='training')
#pdb.set_trace()
validation_generator = multiple_outputs(
val_datagen,
image_dir=train_folder,
dataframe = val_df,
directory = None,
x_col='FileName',
y_col='Label',
image_sizeW=48, image_sizeH=128,
batch_size=batch_size,
subset='validation')
num_train_samples = (len(train_samples))
num_validation_samples = len(validation_samples)
و به این صورت fit میکنم:
history = custom_model.fit_generator(train_generator, steps_per_epoch= (num_train_samples)//batch_size, validation_data=validation_generator, validation_steps = (num_validation_samples)//batch_size,epochs=25)
اما وقتی fit_generator رو صدا میزنم این خطا رو میده:
File "centerloss_generate.py", line 311, in <module>
history = custom_model.fit_generator(train_generator, steps_per_epoch= (num_train_samples)//batch_size, validation_data=validation_generator, validation_steps = (num_validation_samples)//batch_size,epochs=25)
File "/home/daraei/tensorflownew_gpu3/local/lib/python3.5/site-packages/tensorflow_core/python/keras/engine/training.py", line 1297, in fit_generator
steps_name='steps_per_epoch')
File "/home/daraei/tensorflownew_gpu3/local/lib/python3.5/site-packages/tensorflow_core/python/keras/engine/training_generator.py", line 221, in model_iteration
batch_data = _get_next_batch(generator)
File "/home/daraei/tensorflownew_gpu3/local/lib/python3.5/site-packages/tensorflow_core/python/keras/engine/training_generator.py", line 363, in _get_next_batch
generator_output = next(generator)
File "/home/daraei/tensorflownew_gpu3/local/lib/python3.5/site-packages/tensorflow_core/python/keras/utils/data_utils.py", line 918, in get
six.reraise(*sys.exc_info())
File "/usr/lib/python3/dist-packages/six.py", line 686, in reraise
raise value
File "/home/daraei/tensorflownew_gpu3/local/lib/python3.5/site-packages/tensorflow_core/python/keras/utils/data_utils.py", line 894, in get
inputs = self.queue.get(block=True).get()
File "/usr/lib/python3.5/multiprocessing/pool.py", line 644, in get
raise self._value
File "/usr/lib/python3.5/multiprocessing/pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "/home/daraei/tensorflownew_gpu3/local/lib/python3.5/site-packages/tensorflow_core/python/keras/utils/data_utils.py", line 828, in next_sample
return six.next(_SHARED_SEQUENCES[uid])
File "centerloss_generate.py", line 120, in multiple_outputs
subset=subset)
File "/home/daraei/tensorflownew_gpu3/local/lib/python3.5/site-packages/keras_preprocessing/image/image_data_generator.py", line 683, in flow_from_dataframe
validate_filenames=validate_filenames
File "/home/daraei/tensorflownew_gpu3/local/lib/python3.5/site-packages/keras_preprocessing/image/dataframe_iterator.py", line 124, in __init__
df = dataframe.copy()
AttributeError: 'str' object has no attribute 'copy'
خیلی جستجو کردم ولی چیزی به دست نیاوردم. ممنون میشم اگر کمکم کنید.. با تشکر!!