2

I suspect google colab is not using GPU, if I use theano as backend with Keras. Same code trains at the rate of ~4min per epoc, if back end is Tensorflow, but takes 7 hours per epoc with theano as back end. I did following steps to modify keras configuration

!cp .keras/keras.json .keras/keras.json.tf
!cp drive/MachineLearning/kerasJson/keras.json .keras/keras.json
!cat .keras/keras.json

keras.json for theano looks like

{
    "floatx": "float32",
    "epsilon": 1e-07,
    "backend": "theano",
    "image_dim_ordering": "th",
    "image_data_format": "channels_first"
}

keras.json for tensorflow looks like

{
    "floatx": "float32",
    "epsilon": 1e-07,
    "backend": "tensorflow",
    "image_data_format": "channels_last"
}

With theano backend same code timing looks like

drive/MachineLearning/data/NLP/keras_spell_e2.h5

/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:268: UserWarning: Update your `fit_generator` call to the Keras 2 API: `fit_generator(<generator..., steps_per_epoch=100, epochs=500, verbose=1, callbacks=[<__main__..., validation_data=<generator..., validation_steps=10, class_weight=None, workers=1, initial_epoch=0, use_multiprocessing=False, max_queue_size=10)`

Epoch 1/500
  2/100 [..............................] - ETA: 6:58:52 - loss: 0.5325 - acc: 0.4895

But with tensorflow, it takes 4-5 min

drive/MachineLearning/data/NLP/keras_spell_e2.h5

/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:268: UserWarning: Update your `fit_generator` call to the Keras 2 API: `fit_generator(<generator..., steps_per_epoch=100, epochs=500, verbose=1, callbacks=[<__main__..., validation_data=<generator..., validation_steps=10, class_weight=None, workers=1, initial_epoch=0, use_multiprocessing=False, max_queue_size=10)`

Epoch 1/500
 14/100 [===>..........................] - ETA: 3:45 - loss: 0.5161 - acc: 0.4998

Any help?

Sekar S
  • 163
  • 1
  • 10
  • 1
    Theano seems to fall in popularity. Why not migrating to TF? – korakot Apr 15 '18 at 15:21
  • Actually in my computer tensorflow >1.5.0 does not work as AVX is by default enabled. I might need to spend time to compile it, but not tried it. – Sekar S Apr 29 '18 at 04:53
  • I'm getting the `No such file or directory: '.keras/keras.json'` error. Could you share how you overcame with this (if you did)? – talha06 Jul 06 '20 at 09:36
  • @talha06 you need to create that file. `!cp drive/MachineLearning/kerasJson/keras.json .keras/keras.json` was doing it for me. I used to copy it from my drive to colab. You may need to echo >> to./keras/keras.json or something like that. My only issue was it was not using GPU – Sekar S Jul 07 '20 at 18:09

0 Answers0