I edited Keras .optimizer
and .layers
modules locally, but Colab uses its own Keras & TensorFlow libraries. Uploading then using the edited libs would be rather involved per pathing and package interactions, and an overkill for a few small edits.
The closest I've got to accessing a module is keras.optimizers.__file__
, which gives a relative path I don't know what to do with: '/usr/local/lib/python3.6/dist-packages/keras/optimizers.py'
Can Colab libraries be edited? Permanently (not per-runtime)?
Colab now allows direct access to system files from the GUI itself. There one can view and edit all the installed libraries like one would have done on their pc itself.
Go to the Files icon in the left Sidebar. Go to the Up Folder. From there go to the path
usr/local/lib/python3.6/dist-packages
Here, find the package and make your edit. Then restart the runtime, from Runtime/Restart Runtime option in the menu.
You could fork the libraries on GitHub, push your changes to a new branch and then do.
!pip install git+https://github.com/your-username/keras.git@new-branch
Or even a specific commit
!pip install git+https://github.com/your-username/keras.git@632560d91286
You will need to restart your runtime for the changes to work.
More details here.
Per-runtime solution
import keras.optimizers
with open('optimizers.txt','r') as writer_file:
contents_to_write = writer_file.read()
with open(keras.optimizers.__file__,'w') as file_to_overwrite:
file_to_overwrite.write(contents_to_write)
>>Restart runtime (do not 'Reset all runtimes')
.__file__
, (3) 'Reset all runtimes' restores Colab modules - use if module breaks
Considering its simplicity, it's as good as a permanent fix. For possibly better scalability, see fizzybear's solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With