Wiki: Lesson 1

Hello,

I found out from the first lesson that I have to configure web services like ‘paperspace’. But, I have a laptop with GTX1050, is it not possible to configure this GPU itself and run the programs??

Please help me understand this.

Thank you!
Anil

It’s obviously possible with a 1050…

1 Like

I came across the same issue last week when I was trying to set up my machine. I waited about 3 days before I sent a support ticket and they approved my request within 24 hours after.

I am using Google Cloud Computing, I get 300$ credit free when register. I follow this guide https://medium.com/@howkhang/ultimate-guide-to-setting-up-a-google-cloud-machine-for-fast-ai-version-2-f374208be43 for setup. It take 2-3 days for the step increasing GPU quotas. Everything works fine.

1 Like

As long as your GPU has CUDA 3.0 you’re good to go. I has GTX 745 but still works fine.

1 Like

Hi, I had run the lesson 1 notebook earlier on Google Colab without any issue. However yesterday when I tried to re-run it, facing below error.
AxisError: axis 1 is out of bounds for array of dimension 1

The notebook is same as what @manikanta_s put up in this post here

Step: Fine-tuning and differential learning rate annealing
Code:

log_preds,y = learn.TTA()
probs = np.mean(np.exp(log_preds),0)
accuracy(probs, y) <<<<< Error in this line

Error:
---------------------------------------------------------------------------
AxisError Traceback (most recent call last)
in ()
----> 1 accuracy(probs, y)

/usr/local/lib/python3.6/dist-packages/fastai/metrics.py in accuracy(preds, targs)
      3 
      4 def accuracy(preds, targs):
----> 5     preds = np.argmax(preds, axis=1)
      6     return (preds==targs).mean()
      7 

/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in argmax(a, axis, out)
   1002 
   1003     """
-> 1004     return _wrapfunc(a, 'argmax', axis=axis, out=out)
   1005 
   1006 

/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
     50 def _wrapfunc(obj, method, *args, **kwds):
     51     try:
---> 52         return getattr(obj, method)(*args, **kwds)
     53 
     54     # An AttributeError occurs if the object does not have

AxisError: axis 1 is out of bounds for array of dimension 1

Any idea why I am getting this error now?

-Thanks
Nikhil

1 Like

Well, looks like ‘log_preds’ should be used instead of ‘probs’. Is this a recent change in the accuracy function? Thanks.

1 Like

Hi,

Thanks for the reply!
I am new to these GPU configurations. Could you please clarify my below thoughts.

  1. We use WEB services for training when one does not have a GPU in his\her PC.
  2. If the appropriate GPU is available in PC, we do not need to use any WEB services. Right? We just have to configure the GPU available on PC for training.

If my understanding is correct, how do I configure GPU on my laptop for trainin g?

Thank you!
Anil

Try updating your fastai library first. Since the current metrics.py module is

from .imports import *
from .torch_imports import *

def accuracy_np(preds, targs):
preds = np.argmax(preds, 1)
return (preds==targs).mean()

def accuracy(preds, targs):
preds = torch.max(preds, dim=1)[1]
return (preds==targs).float().mean()

def accuracy_thresh(thresh):
return lambda preds,targs: accuracy_multi(preds, targs, thresh)

def accuracy_multi(preds, targs, thresh):
return ((preds>thresh).float()==targs).float().mean()

Notice the different between your accuray() and the current up-to-date accuracy() function. Then, try using the current up-to-date notebook. For that part code it is now (using accuracy_np() )

log_preds,y = learn.TTA()
probs = np.mean(np.exp(log_preds),0)
accuracy_np(probs, y)

Further, check out the dimension of log_preds, and probs in your code. log_preds should be a 3D-array, then after average over the first dimension, probs should be a 2D-array. If probs is not a 2D-array, you get that error.

1 Like

To get through this course GPU is required. You can have it by using cloud services like AWS, Paperspace, GCP, … or you have it on your own computer. In either cases, you need to set up the environment to run the course’s notebooks. Set up might take a lot of time and hassle depending on what platform you choose. The easiest way is using Paperspace and the hardest way might be to configure your own computer. Please refer to this excellent repo where @reshama documented how to configure platforms for this course.

1 Like

Is there an alternative to Paperspace that does not require weeks of waiting to get access to the GPU instances?

Crestle is a quick and easy alternative to Paperspace @nyxynyx

Google Cloud Compute is a good option. I follow this guide last week https://medium.com/@howkhang/ultimate-guide-to-setting-up-a-google-cloud-machine-for-fast-ai-version-2-f374208be43 to setup the platform for this course and it works well. Just one thing is that it took 2-3 days waiting Google to approve GPU quotas request but you gonna got 300$ credits free which is 300 hours, enough to explore the course.

2 Likes

Thanks for your response.
The notebook does a “!pip install fastai” at the beginning. So perhaps the package needs to be updated at the source.

In my case, I see log_preds is 2D array and probs is 1D. I understood what the error was hence replaced probs with log_preds and everything worked. Just need to figure out now if with that change it is working as intended. :slightly_smiling_face: Thanks.

Found it perfect to listen to that CNN Mini Episode while training my network!

I set up Paperspace yesterday and there was actually very little time needed.
It took me 2 tries though. The first one got stuck loading when trying to open. I removed that one and created a new machine, that one loaded up in seconds.

Hello all,
Just to share one more experience with paperspace - I signed up today around 6 hours ago, tried to set up a machine with no luck so far. After couple of hours of waiting I created a ticket to support, and that’s the info I got from them recently by email:

Thanks for reaching out, and apologies for the delay on your request. Typically we’re able to get users approved within a couple hours With a surge in requests for these instance types, we’re a little behind. We’re in the process of adding capacity right now, so please sit tight and you’ll get a notification the moment a seat is available. We appreciate your patience!

So, waiting…
Hope this helps.

P.S. Meanwhile setting up crestle took 2 minutes and 3 clicks, and allowed to successfully go through the 1st lesson :wink:

I have questions about cell 15 from the Lesson1 Notebook about precomputed activations.

# Uncomment the below if you need to reset your precomputed activations# #shutil.rmtree(f'{PATH}tmp', ignore_errors=True)

  1. Why does learn.fit(0.01, 2) in the next cell execute faster with precomputed activations and slower if I execute shutil.rmtree(f'{PATH}tmp', ignore_errors=True) ? Isnt it running learn.fit on the same data in either case (i.e data from dogscats/train)

  2. If I delete the precomputed activations, how do I get them back? Do I have to do a fresh download of the “tmp” folder from the paperspace script?

  3. Just to clarify using precomputed activations - our network has already learned weights using a large image data and we are going to fine-tune them using our “train” folder. Correct?

Thanks a whole bunch
Vikas

1 Like

My models folder is blank. Did anyone else have the same issue?

I am assuming it should not be blank because this is the “pretrained” model we start with in Lesson 1 yes?

Hi,

First let us explained the idea of precomputed activations
Let’s go back to the network, consider resnet50.

resnet50

When finetuning a model we train only the last layer and previous ones (freeze layers) remain unchanged. So all computations on the freeze layers will be the same ie: the result of image 1 (of my training set) going from C1 to FC7 layers will never change or we do it many times with same images. In fact an epoch is a tour over all images of the training set so training during 10 epochs means I’ll do the same computation 10 times. This is a waste, so we take a shortcut, we precompute all training image results from 1st to last fixed layers, here from C1 to FC7 and save them: this is the precomputed activations. In doing so it’ll be fast because we’ll use results of fixed layers computations (precomputed activations) and compute only from FC7 to FC8 for each image.

So the question 1:
The response is clear, it will take much time because it’ll apply all fixed layers to all training images. But the next times will be faster.

Question 2:
No, you have to run fit but make sure to use the attribute precompute=True:
learn.fit(0.01, 2, precompute=True)

Question 3:
Precomputed activations and pretrained weights are two differents things.
Precomputed activations help speeding computations during training a network while pretrained weights are like the level of knowledge acquired by the network after some training on some data.

Hopefully, it helps.

4 Likes