AmarSaini / Epoching-Blog

Yet Another Deep Learning Blog :)
https://amarsaini.github.io/Epoching-Blog/
Apache License 2.0
33 stars 9 forks source link

name 'cnn_config' is not defined #6

Closed timothyvanco closed 3 years ago

timothyvanco commented 3 years ago

Hi, I tried your code written here - https://amarsaini.github.io/Epoching-Blog/jupyter/2020/03/23/Self-Supervision-with-FastAI.html

and here - https://colab.research.google.com/github/AmarSaini/Epoching-Blog/blob/master/_notebooks/2020-03-23-Self-Supervision-with-FastAI.ipynb#scrollTo=DSc-D38OYBQX

and got this error: NameError: name 'cnn_config' is not defined

in this line of code: head_config = cnn_config(lin_ftrs=[])

please can you help me with this issue?

AmarSaini commented 3 years ago

Of course :)

I'll need to run through and maybe update the code to the current version of fastai, I made this notebook before it's official release.

In regards to the error you encountered, cnn_config was used to configure settings to create a custom head in a learner object I believe. Specifically it was used here: image

instead of using config=head_config, one solution could be to make your custom_head yourself and pass it into cnn_learner, as opposed to using a config.

To make a custom head: https://github.com/fastai/fastai/tree/master/fastai/vision/learner.py#L76 And then use the custom_head argument instead of the config argument in your cnn_learner: https://github.com/fastai/fastai/tree/master/fastai/vision/learner.py#L162

timothyvanco commented 3 years ago

Thanks but are you planning to check and update the code sometime soon? Because I also have a problem with

from fastai2.vision.all import *

Because it is outdated or I dont know what is a problem?...

This project looks very good and interesting, so I would like to run it somehow, but I also know, that you have many things to do :) so maybe, if it wont take you much time, I would really appreciate it 👍

AmarSaini commented 3 years ago

I'll revamp the full notebook this weekend for sure! Give me a day or two :)

These problems you are running into are here because I was using fastai2 prior to it's official release into the fastai channel. Some changes have definitely been made since then, I'll correct them all soon!

I should of made these changes upon fastai2's official release into fastai, but I guess better late than never!

timothyvanco commented 3 years ago

Hi, did you have a time to look on it please? :)

AmarSaini commented 3 years ago

Sorry - got caught up with some stuff this weekend! Will have it up this week for sure!

AmarSaini commented 3 years ago

Hey! Check back on Wednesday, It'll be revamped by then & ready to go!

AmarSaini commented 3 years ago

Everything should be good to go! Thanks again for the heads up, let me know if anything else seems glitchy! 😄

timothyvanco commented 3 years ago

Hi, thanks. I tried it now, but I got into a problem with downloading a MNIST dataset. I see that you put there 4 lines of code to try it if I got this issue, but none of them is helping. Still the same problem - HTTPError: HTTP Error 503: Service Unavailable

AmarSaini commented 3 years ago

Is HTTPError: HTTP Error 503: Service Unavailable what you see when using the 4 lines to manually download the files?

The quickest solution would be to visit each of the 4 urls, and manually download the files & put it in data/MNIST/raw/

I'm not sure why PyTorch's dataset downloader is giving that error right now, I ran into it a couple times myself.

timothyvanco commented 3 years ago

This is what I see...

Screenshot 2021-03-11 172807

I think I downloaded it, but I cant run the next cell with:

# Make rotation datasets
train_ds = Custom_Dataset_MNIST('data/MNIST/processed/training.pt', pct=1.0, classification=False)
valid_ds = Custom_Dataset_MNIST('data/MNIST/processed/test.pt', pct=1.0, classification=False)
print('{0} Training Samples | {1} Validation Samples'.format(len(train_ds), len(valid_ds)))
AmarSaini commented 3 years ago

Looks like it wasn't able to download it using the 4 lines. HTTP request sent, awaiting response... 503 Service Unavailable

Click on each of the 4 links individually, then download them yourself & move/upload all 4 of them to data/MNIST/raw

After that, you should be good to go!

timothyvanco commented 3 years ago

Thanks, I done it like this, But still got a problem in Making rotation datasets - I have files just in "raw" folder but nothing in "processed" folder, so I got problem in next section after downloading (I mentioned it in the end of previous comment). So I got this error:

FileNotFoundError: [Errno 2] No such file or directory: 'data/MNIST/processed/training.pt'

AmarSaini commented 3 years ago

After manually moving the files to data/MNIST/raw, go ahead and try that PyTorch dataset download cell again (the one that errored out).

Run this cell: torchvision.datasets.MNIST('data/', download=True)

Now that the files are already there, it shouldn't try to re-download them. It'll just skip to processing them.

If it tries to download them, then I'm guessing you didn't move/upload the files in the right location/directory.

Let me know if it works!

timothyvanco commented 3 years ago

Yeah! Thanks, it is running smooth and goood!! :) I am thinking about changing dataset to Cifar10 for example. What do you think? I hope, it wont be so hard to change... I will try :)

AmarSaini commented 3 years ago

Good to hear!

And that's nice idea about trying it on Cifar10, it should be an interesting experiment!

You may have to play with the number of samples to see where the benefit of self-supervised learning comes in! (i.e. with MNIST, we were able to show an improvement at 0.3% samples)

Keep me updated if you try it!

timothyvanco commented 3 years ago

Yeah of course, I am trying to run few algorithm in Self-Supervision. Mainly SimCLR, MoCOv2 and BYOL. Your Rotation is another one which is really great to learn new pre-text task method. I will try to modify it and then upload to my github and send you a link. Maybe you will find some trick to make it even better :)