Continuing the discussion from Lesson 2 discussion:
Hi,
I am currently working on a regression problem where the model needs to count the number of connectors in a pic. I have only 120 labeled data points split into 100 training and 20 validation samples. The directory names are numbers indicating the count of connectors.
I have been able to modify the labels from get_data() and do a model.fit on the resultant data. Given the limited samples, have to do heavy data augmentation. So would like to train the model using fit_generator. However am running into problems with fit_generator.
my code is as follows
batches= gen.flow_from_directory(dirname,target_size=target_size,class_mode='categorical', shuffle=True, batch_size=batch_size) imgs,labels=next(batches) re_label=np.dot(labels,indices) for x in range(batch_size): re_label[x]=lookup[int(re_label[x])] yield (imgs,re_label)
However, get the following error when I run this above code.
File “C:\Users\satish\Anaconda\lib\site-packages\keras\engine\training.py”, line 436, in data_generator_task
generator_output = next(generator)
TypeError: function object is not an iterator
Exception Traceback (most recent call last)
in ()
1 model_v.compile(optimizer=Adam(1e-6),
2 loss=‘mse’)
----> 3 model_v.fit_generator(get_batches_t,nb_epoch=1,samples_per_epoch=500,validation_data=(val1,val2),nb_val_samples=100,verbose=1)
C:\Users\satish\Anaconda\lib\site-packages\keras\models.pyc in fit_generator(self, generator, samples_per_epoch, nb_epoch, verbose, callbacks, validation_data, nb_val_samples, class_weight, max_q_size, nb_worker, pickle_safe, **kwargs)
895 max_q_size=max_q_size,
896 nb_worker=nb_worker,
→ 897 pickle_safe=pickle_safe)
898
899 def evaluate_generator(self, generator, val_samples,
C:\Users\satish\Anaconda\lib\site-packages\keras\engine\training.pyc in fit_generator(self, generator, samples_per_epoch, nb_epoch, verbose, callbacks, validation_data, nb_val_samples, class_weight, max_q_size, nb_worker, pickle_safe, initial_epoch)
1447 raise Exception('output of generator should be a tuple ’
1448 '(x, y, sample_weight) ’
→ 1449 'or (x, y). Found: ’ + str(generator_output))
1450 if len(generator_output) == 2:
1451 x, y = generator_output
Exception: output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: None
Not sure why it says generator output is not a tuple.