Updated super-res for v2?

Hi all,

Just starting out trying the learn all the changes brought about in fastai v2.

One of my favorite projects was the superres notebooks from the v1 course. I had made my own models to try to deblur using the same techniques, but with v2 I don’t even know where to begin to load and use the model on a new photo. I know I need to change my thinking from giving the unet_learner ‘data’ to giving it a data-loader, but I’m really stuck.

Has anyone already tried to convert to fastai v2 the super-res notebook, and in particular this one: lesson7-superres.ipynb? Will I have to retrain a new model using fastai v2?

Any help or pointers would be greatly appreciated!

The entire v3 course ported to v2 (part 1) can be found here:

superres is included https://github.com/fastai/fastai/blob/master/dev_nbs/course/lesson7-superres.ipynb

Oh wow! I didn’t even realize, thanks!

Sorry, back to my 2nd question - can we use a model trained with v1 for v2? When trying to load the model, I’m getting a lot of errors:
learn = unet_learner(dls, arch, loss_func=F.l1_loss, blur=True, norm_type=NormType.Weight)

RuntimeError: Error(s) in loading state_dict for DynamicUnet:
	Missing key(s) in state_dict: "layers.3.0.0.weight", "layers.3.1.0.weight", "layers.4.shuf.0.0.weight", "layers.4.shuf.0.0.bias", "layers.4.conv1.0.weight", "layers.4.conv2.0.weight", "layers.5.shuf.0.0.weight", "layers.5.shuf.0.0.bias", "layers.5.conv1.0.weight", "layers.5.conv2.0.weight", "layers.6.shuf.0.0.weight", "layers.6.shuf.0.0.bias", "layers.6.conv1.0.weight", "layers.6.conv2.0.weight", "layers.7.shuf.0.0.weight", "layers.7.shuf.0.0.bias", "layers.7.conv1.0.weight", "layers.7.conv2.0.weight", "layers.8.0.0.weight", "layers.8.0.0.bias", "layers.11.convpath.0.0.weight", "layers.11.convpath.0.0.bias", "layers.11.convpath.1.0.weight", "layers.11.convpath.1.0.bias", "layers.12.0.weight", "layers.12.0.bias". 
	Unexpected key(s) in state_dict: "layers.3.0.0.weight_g", "layers.3.0.0.weight_v", "layers.3.1.0.weight_g", "layers.3.1.0.weight_v", "layers.4.shuf.conv.0.bias", "layers.4.shuf.conv.0.weight_g", "layers.4.shuf.conv.0.weight_v", "layers.4.conv1.0.weight_g", "layers.4.conv1.0.weight_v", "layers.4.conv2.0.weight_g", "layers.4.conv2.0.weight_v", "layers.5.shuf.conv.0.bias", "layers.5.shuf.conv.0.weight_g", "layers.5.shuf.conv.0.weight_v", "layers.5.conv1.0.weight_g", "layers.5.conv1.0.weight_v", "layers.5.conv2.0.weight_g", "layers.5.conv2.0.weight_v", "layers.6.shuf.conv.0.bias", "layers.6.shuf.conv.0.weight_g", "layers.6.shuf.conv.0.weight_v", "layers.6.conv1.0.weight_g", "layers.6.conv1.0.weight_v", "layers.6.conv2.0.weight_g", "layers.6.conv2.0.weight_v", "layers.7.shuf.conv.0.bias", "layers.7.shuf.conv.0.weight_g", "layers.7.shuf.conv.0.weight_v", "layers.7.conv1.0.weight_g", "layers.7.conv1.0.weight_v", "layers.7.conv2.0.weight_g", "layers.7.conv2.0.weight_v", "layers.8.conv.0.bias", "layers.8.conv.0.weight_g", "layers.8.conv.0.weight_v", "layers.10.layers.0.0.bias", "layers.10.layers.0.0.weight_g", "layers.10.layers.0.0.weight_v", "layers.10.layers.1.0.bias", "layers.10.layers.1.0.weight_g", "layers.10.layers.1.0.weight_v", "layers.11.0.bias", "layers.11.0.weight_g", "layers.11.0.weight_v". 

Not if the model definition changed. V2 is a complete rewrite, which includes the unet, as you’ve seen :slight_smile:

You’d need to make a model with the old unet code to make it work.


I’m revisiting this notebook and rebuilding my models now that fastai changed the way models were saved.

Unfortunately, the following code is providing errors for unet_config: not defined. Is there a workaround for this? I’m not familiar with what this bit of code is doing so not sure how to replace it.

learn = unet_learner(dls, arch, loss_func=feat_loss, metrics=LossMetrics(feat_loss.metric_names),
                     config=unet_config(blur=True, norm_type=NormType.Weight))

I double checked and this is the same in the master, here: fastai/lesson7-superres.ipynb at master · fastai/fastai · GitHub

I solved my own problem - looks like the arguments are passed directly like so:

learn = unet_learner(dls, arch, loss_func=feat_loss, metrics=LossMetrics(feat_loss.metric_names),
                     blur=True, norm_type=NormType.Weight)