jupyter colab

I have an older ’09 Macbook Pro and had trouble while trying to run the latest Keras to use for my latest Flatiron school neural network projects. The older Mac only updates to El Capitan, so it’s unable to run the latest versions of Keras in Jupyter notebooks. To get around this, I have been trying to integrate the use of Google Colab with my workflow. Colab is a cloud-based notebook and has the needed updates to run Keras and has come in handy. Trying to learn the small differences between Jupyter notebooks and Colab in order to keep everything flowing smoothly and all my changes synced has been challenging. Here is a little workflow that I’ve found useful in managing my notebooks and Github repositories. It’s not the most elegant but I have found it to be useful and it gets the job done for now, while I continue to learn more about using Colab and all of it’s connections to Github.

我有一个较旧的'09 Macbook Pro,在尝试运行最新的Keras用于我的Flatiron学校最新神经网络项目时遇到了麻烦。 较旧的Mac仅更新到El Capitan,因此它无法在Jupyter笔记本中运行最新版本的Keras。 为了解决这个问题,我一直在尝试将Google Colab的使用与我的工作流程集成在一起。 Colab是基于云的笔记本,具有运行Keras所需的更新,并且派上了用场。 试图了解Jupyter笔记本电脑和Colab之间的细微差异,以使一切顺畅进行并同步所有更改,这一直是具有挑战性的。 我发现这里有一些工作流程对管理笔记本和Github存储库很有用。 它不是最优雅,但我发现它很有用,并且现在可以完成工作,与此同时,我继续学习有关使用Colab及其与Github的所有连接的更多信息。

(1. Create a repository in Github.)

If you already have a repository you want to work with, then move to step two of this process to create or open a Colab notebook. If you need to make a whole new repository to start with, go to Github and create a new one. Click the green “New” button under the repository section.

如果您已经有要使用的存储库,则转到此过程的第二步以创建或打开Colab笔记本。 如果您需要从头开始建立一个全新的存储库,请转到Github并创建一个新的存储库。 单击存储库部分下方的绿色“新建”按钮。

Click the green button to create a new repo. 单击绿色按钮创建一个新的仓库。

Add a name for the repository on the next screen, and click the box to initialize a README. You can choose to add a license to the repository, though I am still learning about all of the different types there are and won’t go into detail about that in this article. Here’s a good link I found about the differences between some of them for you to check out. https://www.fastcompany.com/3014553/what-coders-should-know-about-copyright-licensing. Then click “create repository”.

在下一个屏幕上为存储库添加一个名称,然后单击该框以初始化README。 您可以选择向存储库添加许可证,尽管我仍在学习其中存在的所有不同类型,并且在本文中不会对此进行详细介绍。 我找到了一个很好的链接,其中有一些区别供您查看。 https://www.fastcompany.com/3014553/what-coders-should-know-about-copyright-licensing 。 然后单击“创建存储库”。

The next screen will be a sort of blank slate repository which shows your README file which you can leave alone for now and head over to Google Drive.

下一个屏幕是空白的空白存储库,其中显示了您的README文件,您可以暂时保留该文件,然后转到Google云端硬盘。

(2. Create or open a Colab notebook in Google Drive.)

In Google Drive, click the “New” button, go to “More” and select “Google Colaboratory”. If Colab doesn’t show up in this drop down, you should be able to find it by clicking on “Connect more apps”.

在Google云端硬盘中,点击“新建”按钮,转到“更多”,然后选择“ Google合作实验室”。 如果该下拉菜单中未显示Colab,则您应该可以通过单击“连接更多应用”来找到它。

Click New. 单击新建。

Go to More. 转到更多。

Click Google Colaboratory. 点击Google合作实验室。

A new Colab notebook tab will open. This will serve as your new notebook to work with and eventually save to your Github repo. If you already had an existing repo and notebook and would like to open it in Colab, on the top menu bar click “File”, “Open notebook”.

一个新的Colab笔记本选项卡将打开。 这将作为您可以使用的新笔记本,并最终保存到您的Github存储库中。 如果您已经有一个现有的存储库和笔记本,并且想在Colab中打开它,请在顶部菜单栏上单击“文件”,“打开笔记本”。

Click Open notebook. 单击打开笔记本。

A new pop up will appear. Click “Github” on the top. You may need to enter your Github credentials here to connect to Colab if you haven’t already done so in the past. If it’s connected you should see a screen like this, showing your Github username in the search bar. Make sure you have the check the box “Include private repos” in case your existing repo is not public. A dropdown menu of your repositories will be underneath and you can select the one you created. Once selected, if you had an existing notebook on the Github repository it should show up underneath and you can click on that to open it in a new Colab tab and continue to work on it.

将会出现一个新的弹出窗口。 点击顶部的“ Github”。 如果您以前没有这样做,则可能需要在此处输入Github凭据才能连接到Colab。 如果已连接,您应该会看到一个类似的屏幕,在搜索栏中显示您的Github用户名。 如果您现有的仓库不是公开的,请确保选中“包括私人仓库”复选框。 存储库的下拉菜单将在下面,您可以选择创建的存储库。 选中后,如果您在Github存储库中已有一个笔记本,则该笔记本应显示在下面,您可以单击该笔记本在新的Colab选项卡中将其打开,然后继续进行操作。

The existing notebook shows up underneath the dropdown. 现有笔记本显示在下拉菜单的下方。

(3. Save notebook to Github.)

Make your changes and edits to your Colab notebook. Feel free to give it a title on the top bar. Next, to save it to your repository, go to the File menu. Click “Save a copy in Github”.

对您的Colab笔记本进行更改和编辑。 随时在顶部栏上给它一个标题。 接下来,要将其保存到存储库中,请转到“文件”菜单。 点击“在Github中保存副本”。

A pop up will appear. Select your repo from the dropdown list, and add a commit message for the push. Check the box “Include a link to Colaboratory”, which will add a shortcut button to the top of your notebook for quick access.

将会出现一个弹出窗口。 从下拉列表中选择您的仓库,并为推送添加提交消息。 选中“包括协作的链接”框,该框将在笔记本顶部添加一个快捷按钮,以便快速访问。

Click “OK” and a new tab will open to your notebook commit on Github. You’ll see it has the “Open in Colab” shortcut button at the top of the notebook. Now you can click on that whenever you want to quickly open it back up in Colab and make changes. Then just repeat the save process to push back to Github. You also have the option to open the Colab notebook directly from your Google Drive.

单击“确定”,一个新选项卡将打开,您的笔记本在Github上提交。 您会看到它在笔记本顶部具有“在Colab中打开”快捷按钮。 现在,您可以随时单击它,以在Colab中快速将其备份并进行更改。 然后,只需重复保存过程即可返回到Github。 您还可以选择直接从Google云端硬盘打开Colab笔记本。

(Side note:)

If the Colab notebook is saved to Github, and then reopened in Colab using the shortcut button, it will not autosave changes and will need to be saved to Github from the Colab File menu in order to push changes to Github like in step three above. If you try to click save from the File menu, you’ll get a pop up box like this.

如果将Colab笔记本保存到Github,然后使用快捷按钮在Colab中重新打开,它将不会自动保存更改,因此需要从Colab文件菜单将其保存到Github,以便像上面的第三步一样将更改推送到Github。 如果尝试从“文件”菜单中单击“保存”,则会出现一个类似这样的弹出框。

If you prefer to just have the Colab notebook autosave, then you can just work on that Colab notebook independently by opening it up from Google Drive instead of opening it from Github with the shortcut button.

如果您只希望自动保存Colab笔记本,则可以通过从Google云端硬盘打开它而不是使用快捷按钮从Github打开它来独立处理该Colab笔记本。

No matter whether you are opening the file from Google Drive or from Github, you should still save it to Github same as shown before in step three in order to push your changes to the Github repository.

无论您是从Google云端硬盘还是从Github打开文件,都仍应将其保存到第3步中所示的相同文件中,以便将更改推送到Github存储库。

(4. Sync with local repo on desktop)

Once the notebook is saved on Github, if you’d like to also back it up on your local machine or work on it locally, use Terminal or Github Desktop and clone it to your computer. I can help you with that if you need to know how to clone it. Just leave a comment, otherwise I can make a separate story about it.

将笔记本保存在Github上后,如果您还希望将其备份到本地计算机上或在本地上使用它,请使用Terminal或Github Desktop将其克隆到计算机上。 如果您需要知道如何克隆它,我可以为您提供帮助。 请发表评论,否则我可以做一个单独的故事。

If changes to the notebook are made from your local machine, you can push those like normal back to Github. Want to open it back up in Colab? Go to the notebook on the Github repo and click the Colab button at the top of the notebook. It’ll open in a new Colab tab, and you’ll see all of the new changes you just made previously on your local machine.

如果在本地计算机上对笔记本进行了更改,则可以像平常一样将其推送回Github。 是否想在Colab中打开备份? 转到Github存储库上的笔记本,然后单击笔记本顶部的Colab按钮。 它将在新的Colab标签中打开,您将看到之前在本地计算机上所做的所有新更改。

There are definitely more elegant ways of doing this, but this is just a quick and easy way that I’ve found to be useful while coming across obstacles like not being able to run Keras in Jupyter notebooks on my local machine and Colab has proven to be a nice workaround without having to drop money on some new laptop during these difficult economic times. Hope this helps some others out there who are just getting familiar with Github, Colab and Jupyter.

肯定有更优雅的方法可以做到这一点,但这只是一种快捷简便的方法,我发现它在遇到障碍时会很有用,例如无法在本地计算机上的Jupyter笔记本中运行Keras,而Colab已证明可以这是一个不错的解决方法,而不必在经济困难时期购买新笔记本电脑。 希望这对其他刚刚熟悉Github,Colab和Jupyter的人有所帮助。

翻译自: https://medium.com/analytics-vidhya/a-quick-workflow-for-google-colab-github-and-jupyter-notebooks-on-mac-ff5d004e01f

jupyter colab