如何编辑Google合作实验室? [英] How to edit Google Colaboratory libraries?

查看:71
本文介绍了如何编辑Google合作实验室?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地编辑了Keras .optimizer .layers 模块,但是Colab使用了自己的Keras&TensorFlow库.然后,使用路径和程序包交互会涉及上载然后使用已编辑的库进行上传,而对于少量的小编辑则显得过分杀伤.

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.

我访问模块最接近的是 keras.optimizers .__ file __ ,它提供了一个我不知道该怎么做的相对路径:'/usr/local/lib/python3.6/dist-packages/keras/optimizers.py'

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'

可以编辑Colab库吗?永久(不是按运行时间)?

Can Colab libraries be edited? Permanently (not per-runtime)?

推荐答案

每次运行时解决方案

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)

>>重新启动运行时(不要重置所有运行时")


为了明确起见,(1)将感兴趣的已编辑模块另存为 .txt (2)通过用保存的模块覆盖Colab模块> .__ file __ (3)'重置所有运行时'可恢复Colab模块-如果模块中断则使用

>>Restart runtime (do not 'Reset all runtimes')


To clarify, (1) save edited module of interest as a .txt, (2) overwrite Colab module with the saved module via .__file__, (3) 'Reset all runtimes' restores Colab modules - use if module breaks

考虑到其简单性,它与永久性修复一样好.要获得更好的可伸缩性,请参阅fizzybear的解决方案.

Considering its simplicity, it's as good as a permanent fix. For possibly better scalability, see fizzybear's solution.

这篇关于如何编辑Google合作实验室?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆