0

I am working on cifar10 dataset with Resnet18 architecture. My need is now to reach 94 accuracy within 100 secs. So i have been advised to check validation accuracy only for the last 3 epochs. Anyone help me how to do that ?

from tensorflow.keras.callbacks import ModelCheckpoint,LearningRateScheduler

model.fit_generator(generator=gen,
   steps_per_epoch=np.ceil(50000/512),
   epochs=24,
   validation_data=validation_iterator, 
   verbose=1,
   callbacks =[olr])

The above code checks validation accuracy for all 24 epochs, but i want to check ONLY for last 3 epochs.

L3n95
  • 1,505
  • 3
  • 25
  • 49
  • Have you tried something like this: https://stackoverflow.com/a/54897630/2424980 ? Have an own callback and only do validation if `epoch > your_desired_number` – L3n95 Aug 17 '19 at 13:49
  • The idea of looking validation accuray mostly is yo see if your model overfit or not. With just 3 epochs of 24 you cant see that. – OSainz Aug 17 '19 at 13:50
  • @L3n95. it still not working. from sklearn.metrics import r2_score class MetricsCallback(tf.keras.callbacks.Callback): def on_epoch_end(self, epoch, logs=None): if epoch>2: predictions = self.model.evaluate_generator(validation_iterator, steps = len(validation_iterator)) #print('r2:', r2_score(prediction, y_test).round(2)) model.fit_generator(generator=gen,steps_per_epoch=np.ceil(50000/512), epochs=4, validation_data = validation_iterator,verbose=1,callbacks =[MetricsCallback()]) – Raajesh L R Aug 17 '19 at 14:35
  • Please do **not** use the comments space to provide code - it is literally unreadable! Edit & update your post instead. – desertnaut Aug 17 '19 at 17:43

1 Answers1

0

You may break training into two separate phases in the latter you provide validation data:

model.fit_generator(generator=gen,
   steps_per_epoch=np.ceil(50000/512),
   epochs=21,
   verbose=1,
   callbacks =[olr])

model.fit_generator(generator=gen,
   steps_per_epoch=np.ceil(50000/512),
   epochs=24,
   validation_data=validation_iterator, 
   verbose=1,
   callbacks =[olr],
   initial_epoch=21)
Mehraban
  • 3,164
  • 4
  • 37
  • 60