A walk with fastai2 - Vision - Study Group and Online Lectures Megathread

so not related to this?
The reason i ask is what if (rather when)google fixes that bug then how do we run it :slight_smile: ?

Iā€™m unsure. Probably choose a smaller image size for your transfer image. Or shrink it down via a transform (since it is a TensorImage).

To the no_grad and eval, no. See above discussion where I said why their different.

No_grad never updates for evaluation weights. Only gradients. And vice versa

oh shoot yeah. :upside_down_face:

1 Like

Thatā€™s why I brought it into further discussion, very easy to get confused :smiley:

So to lay this out:
We are using vgg19 to calc the feature loss. We are using a pre-trained model so all the weights are calc.
We are using vgg19 in inference mode ie .eval (to calc the activation at different layers).
The purpose of .eval is to appropriately change the behaviour of bn and dropout layers. But our vgg19 doesnā€™t have any of those? (so why is .eval being used :slight_smile: ? ) is .eval effecting something else ?
Because by default a model is in model.train mode so we use .eval to change the mode.

no_grad can be used with .eval for saving space. (they CAN"T be used interchangeably)
model.train() and model.eval() do not change any behavior of the gradient calculations.

model.eval()
for batch in val_loader:
    #some code
vs
model.eval()
with torch.no_grad():
    for batch in val_loader:
        #some code

The first approach is enough to get correct results. The second approach will additionally save some memory.

@muellerzr am i missing anything? please edit it if i am :slight_smile:
Thanks.

Iā€™m not sure, but eval already disables grad. Thatsā€™ the major diffence between modes. So, no need to additionally disable it - mentioned either on forums or lecturesā€¦

It doesnā€™t. (See the very last post on that thread). Itā€™s still calculated. We can disable it to save memory.

Now for a bigger question which could help us all explore the code:

What does get_preds in fastai2 default to doing? For where to start, check Learner.py :slight_smile:

1 Like

Still donā€™t understand a use case where you would want to calc gradients in the eval mode though :thinking: :thinking:

1 Like

The answer (Atleast for learn.validate()) is we donā€™t calculate the gradients:

So we can see on GatherPredsCallback during begin_validate we see the model set to eval:

Later, if we go look at _do_epoch_validate (on Learner), we find our with torch.no_grad():

Just to clarify-

You mean during evaluation we set it in eval mode and turn off grad calculations right ?

Correct :slight_smile: Iā€™ll put that in real quick

Edited the post before this

1 Like

Video for tonight

4 Likes

Yes, the category ids are not continuous so sorting them out as @muellerzr will unfortunately not work. Right now I am just ignoring the category ids - getting the mask - mapping back the mask to the correct category idā€¦ it works but it feels very inefficientā€¦

1 Like

Thanks guys for joining! :slight_smile:

A few notes from today:

Jeremyā€™s Object Detection Lesson: here
RetinaNet Paper: here
Relevant source code for predictions (may break, have not looked at this for a few days): here
Single Point Regression (headpose): here

(remind me if thereā€™s anything else I missed to link)

2 Likes

One thing not mentioned was the heatmap that Iā€™ve spoken about. This is due to I was not able to successfully train the model well. However, if it is of interest I can release the source code and do a quick walk through video describing the technique and how I went about the dataloader if people would be interested. Let me know :slight_smile:

5 Likes

Replying to let you know Iā€™m interested

2 Likes

@muellerzr I donā€™t understand how fastai2 decides to apply transforms, I mean for Keypoint regression if input is transformed the output should also be transformed, For example, If Resize is applied as item_tfms, the output is transformed by the same function?, or how is that handled?, lets say if my input is a rotated image and output is always a straight image, In this case I just want to apply rotation only to my inputs, how would I do that?

Yes. If we think about keypoints we need to adjust our yā€™s along with it, remember our KeypointScalar transform we made a few lessons back. The transforms are run by TypeDispatch, where if we use a transform, if our input is what that transform is expecting, it will run it. IE Resize for instance looks like so (not exact but close):

class Resize():
def encodes(x:[TensorPoint, TensorImage])

1 Like

Got it! But what if I need my input images to be transformed but not the output image, how would I do that?