Part 2 Lesson 14 Wiki

(Rohit Singh) #126

The normed parameter needs to be True above, as the predictions and targets would also have been normalized.

Here are a couple results of my attempt with super-resolution on satellite imagery… it’s amazing!



It’s looking like something out of ‘Enemy of the State’! :slight_smile:

(Arvind Nagaraj) #127

I was thinking the same!

(Rohit Singh) #128

My labeled data is not perfect, but the results of road detection on satellite imagery are surely encouraging. Imagine getting road networks for remote places in a snap without the costly digitization!

(Ravi Sekar Vijayakumar) #129

Next steps:

(Daniel Hunter) #130

Does anyone know what this line is doing in the carvana notebook?


I checked the source code and I’m really confused:

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

and then:

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

what’s going on here? In accuracy_thresh(), where are the 2 arguments to the lambda function pred,targs, coming from? It appears to be comparing the predictions to the targets (but only the predictions above a certain threshold), but I can’t figure out how it’s actually working. Where is the info coming from? Are there some global variables or something I’m missing?

[EDIT]: Leaving this here for anyone who is also confused — I figured it out. It’s creating the function object and then returning it, and it’s used in fit().

(Even Oldridge) #131

Along the lines of the CSI enhance, and very similar to the work done in this lesson there’s a very impressive paper where they trained a net to produce an image with a longer exposure for low light photography.

Unfortunately no source code, but this could make for an interesting project.

(Sam) #132

In enhance.ipynb…in cell 16 next is supposed to get next batch from the dataloader

x,y = next(iter(md.val_dl))

in cell 17 idx=1, which I expected is the index relative to the batch and an image is shown.

However even if I run x,y = next(iter(md.val_dl)) say 4 times and then run cell 17 I see the same image.

This is not expected. Can someone run an experiment and confirm this to be the case?

Update: If I use md.trn_dl I do see a different image each time

Thank you all

Thanks to @kosborne this is resolved
It seems that iter(md.val_ld) creates a new iterator. To get the next batch one must code as:
my_iter = iter(md.val_dl) #execute only once)
x,y = next(my_iter)[idx] # execute multiple times to get idx-th image from the batch each time

Thank you all

(bhaskar) #133

it won’t give any warnings that’s it , but it cant load weights. I used to convert weights either way, you can change anything if not working. code is pretty much readable.

(Constantin) #134

About resizing images upfront for MatchedFilesDataset: In the enhance notebook re “super-resolution” you are using a MatchedFilesDataset for retrieving the respective downscaled and hi rez versions of the image, so long.
The resizing is done on the fly using the tfms machinery in Now, for lots of images the resizing done in real-time by CPU for each epoch would eat up considerable amounts of time. It is my understanding that in its current version the get_x() and get_y() methods pull the images from the same self.path, however, we would need two different paths. If you were to use ImageData.resize() you would still refer to the same path, however, correct?
How would you go about to do resizing upfront? Would you sub-class ImageData with a resize method for x and resize_y method for y? And how do I make sure I catch all occurences of self.path in all super-classes?

(Constantin) #135

About checkerboard artifacts and PixelShuffling.
Jeremy explained in detail how to avoid checkerboard artifacts using pixel shuffling. I still have some details I don’t understand: When using scale=2 I couldn’t observe checkerboard, however with scale=4 I do. So, obviously there are some parameters I need to tune.
I found in enhance.ipynb the following:

def upsample(ni, nf, scale):
    layers = []
    for i in range(int(math.log(scale,2))):
        layers += [conv(ni, nf*4), nn.PixelShuffle(2)] 
    return nn.Sequential(*layers)

Jeremy mentioned in the lecture, that the 4 is really 2*2, because of scale 2. So, after some consideration I thought for scales!=2 upsampling should rather be:

def upsample(ni, nf, scale):
    layers = []
    for i in range(int(math.log(scale,scale))):
        layers += [conv(ni, nf*scale**2), nn.PixelShuffle(scale)] 
    return nn.Sequential(*layers)

There still is something fishy, however. I can train a network using this upsample function, but I still get a checkerboard. I also really do not understand the for loop. math.log(scale,scale) comes out to always 1, so that probably isn’t the original intention. If I use math.log(scale,2) I get two conv+pixelshuffle blocks for scale=4. Why would I need that? Wouldn’t the model upscale too much then? So, I tried as above, but that kind of makes the for loop obsolete and still I get artifacts.
Did anyone try scale>2 and could comment about how to upscale and pixel shuffle correctly?

(Ahmed Mhamoud) #136

Is there a simple way to apply the Pytorch ‘PixelShuffle’ operation to 1D data (i.e. working with conv1d) ?

(Fred Guth) #137

The blueish image is because opencv uses BGR as default and matplotlib uses RGB. You have to use cv2.cvtColor to change the colorspace.


How can I apply the learned segmentation model (lesson 14, unet) on a single new test image?

is this the correct way to do it?

trn_tfms,val_tfms = tfms_from_model(models, sz)
im = open_image('/home/data/train-512/test1.png')
im = val_tfms(im)
preds = learn.predict_array(im[None])

How to interpret the result of this in the context of segementation?

Figured the correct version (I guess, please comment if I am wrong with it):

trn_tfms,val_tfms = tfms_from_model(models, sz)
im = open_image('/home/data/train-512/test1.png')
im = val_tfms(im)
py = to_np(learn.model(V(im[None])))
show_img(py[0] >0)


Hello everybody,
I did not follow the course lessons order, as result I have question regarding metrics used in carvana notebook. On which dataset the accuracy_threshold and dice metrics are evaluated: train or validation? I used to see both train and val metrics when fitting the model in keras, but was not be able to figure out how it works here. Thanks.

(hector) #141

@broda accuracy_threshold is not a metric, it is the threshold used to decide which class each pixel belongs to from class probabilities outputted from pixel level softmax layer.

(Raaj) #142

I am sorry if this question is too simple. I believe I do not have enough understanding yet and will have to rewatch and better understand the model structure.
But I’ll be grateful for any help regarding this as currently I cannot afford to retrain the model again and again as I am using someone else’s computer and need to return it at the earliest.
A quick response/help will be appreciated.
I wanted to know about loading the saved model in the enhance notebook.
I ran the notebook enhance. I believe it saved ‘sr-1’
I created a new notebook and defined SrResnet there.
How can i use the ‘sr1’ model that was saved?
m = to_gpu(SrResnet(64, scale))
m = nn.DataParallel(m, [0])
learn = Learner(md, SingleModel(m), opt_fn=optim.Adam)
Is this the correct way? Getting the following unexpected key “features.0.0.weight” in state_dict’

(Cesare) #143

Hi Raaj,
listen carefully to the video, about 0:59:00, in short the notebook is not intended to be run in sequence.