talha06
talha06

Reputation: 6466

How can I overcome the "No such file or directory: '.keras/keras.json'" error on Google Colab?

As the title clearly describes, I'm not able to access the Keras configuration (keras.json) file in order to change its backend as getting the FileNotFoundError: [Errno 2] No such file or directory: '.keras/keras.json' error. How can I access this file on Google Colab?

Here is my script:

with open('.keras/keras.json', 'r', encoding='utf-8') as f:
  print(f.read())

p.s. The related questions did not include any information regarding this. So, might be something new regarding the platform.

Upvotes: 0

Views: 379

Answers (2)

korakot
korakot

Reputation: 40818

To show the file

!cat /root/.keras/keras.json

To write to the file

%%writefile /root/.keras/keras.json
{
    "epsilon": 1e-07, 
    "floatx": "float32", 
    "image_data_format": "channels_last", 
    "backend": "tensorflow"
}

Upvotes: 1

Kota Mori
Kota Mori

Reputation: 6740

That json file is (usually) in "~/.keras" directory. So,

import os
with open(os.path.expanduser('~/.keras/keras.json'), 'r', encoding='utf-8') as f:
  print(f.read())

I get on my colab the following.

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

Upvotes: 0

Related Questions