How can run PyTorch Implementation of AnimeGANv2 on google colab notebook?

Viewed 273

Recently, I crossed to a new GitHub repo for converting images into Paprika style model, which recently got viral.

img

Usually, people use this interface, which takes so long time. I want to train the offered available pre-trained models on Google Colab Notebook and experiment Additional Model Weights, but not only I couldn't manage to run Torch Hub Usage according to instructions but also I couldn't run the face2paint option due to the following error:

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-13-35ffb2517470> in <module>()
----> 1 face2paint = torch.hub.load('bryandlee/animegan2-pytorch:main', 'face2paint', size=512, device="cpu")
      2 
      3 img = Image.open(...).convert("RGB")
      4 out = face2paint(model, img)

8 frames
/usr/lib/python3.7/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
    647 class HTTPDefaultErrorHandler(BaseHandler):
    648     def http_error_default(self, req, fp, code, msg, hdrs):
--> 649         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    650 
    651 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 403: rate limit exceeded 

I can't figure out to resolve this issue to run the model on the Colab notebook. Please feel free to edit or comment on Google Colab Notebook I shared.

1 Answers

Google Colab doesn't like file transfers especially if they are repeated. (This might explain the message: "rate limit exceeded") The best is to have everything on your personal drive. This is what I propose to show you. So, what I do, is to copy the things to my personal google drive. So that I don't have to download it again. It will also bypass a potential problem with torch.hub. I'm not 100% positive, but I think it might work for you. It looks a bit lengthy, but it really take maybe 10 minutes to be up and running.

Please follow closely these instructions.

<<< PART 1 >>>

Go on:

https://colab.research.google.com/

Create a New notebook (you don't care about the name since we will run it only once)

  • Mount your drive (left "Files" window, the corresponding icon with the google drive icon)

  • permit and wait until "drive" appears (you can refresh if it takes too long)

Now, on the new notebook: Add the following 3 lines (note: the "!" sign is important!) :

NOTE: I assume you have a drive/MyDrive/Colab Notebook folder.

!mkdir drive/MyDrive/Colab\ Notebooks/ANIME
!cd drive/MyDrive/Colab\ Notebooks/ANIME
!git clone --recursive https://github.com/bryandlee/animegan2-pytorch.git

Note: git will clone it into the root folder, not on your drive.

So, you have to move it to your drive:

!mv animegan2-pytorch/ drive/MyDrive/Colab\ Notebooks/ANIME

Now you can close this session:

Runtime --> Manage session --> terminate

close the tab

<<< PART 2 >>>

  • Open your google drive:

Go to : drive/Mydrive/Colab\ Notebooks/ANIME/animegan2-pytorch

Launch colab_demo.ipynb (or demo.ipynb) BUT DON'T RUN IT NOW:

Right click on colab_demo.ipynb --> open with Google Colaboratory

Select the introductory text ("Interactive demo...")

Click on "+ Code" to add a cell.

In this cell, paste the following two lines:

from google.colab import drive
drive.mount('/content/drive')

Run this cell (only this one for now!) --> get to URL given --> copy the code, go back to the notebook and paste it

Wait a bit (you can click on "Refresh"). Wait until "drive" appears in the "Files" window. Now your drive is mounted.

In the "Files" window, go to :

drive/MyDrive/Colab Notebooks/ANIME/animegan2-pytorch

Double click on hubconf.py to edit it.

change the "release_url" to:

release_url = "/content/drive/MyDrive/Colab Notebooks/ANIME/animegan2-pytorch/weights"

Don't forget to save it. Once done, you can close "hubconf.py" This will force to use your already downloaded files (no more transfers)

Restart Runtime

Change runtime to GPU:

Runtime --> change runtime type --> GPU (or CPU)

And now, the fun part!

<<< PART 3 >>>

Execute the cells!

For "colab_demo":

click on the "Upload(0)" button that appeared at the end of the notebook.

then click on "start"

Best regards,

Stéphane

Related