No module named `crappify`

In Lesson 7, Jeremy uses the crappify to lower the quality of the pet images. But on the notebook hosted on Github lesson7-superres-gan.ipynb, the function has been replaced by the import statement from crappify import *. Where is the crappify module ?

I am getting the error ModuleNotFoundError: No module named 'crappify' on v1.0.52.

3 Likes

I have the same issue

crappify.py is a python file in the same lessons folder here.

5 Likes

I am running code on google colab and getting “No module crappify”. How to overcome this?

easiest for such a short method: copy the contents of that file into a code cell in your notebook.
You can just replace the crappify import with the code.

Alternative: wget the .py file.

1 Like

I found a simple solution to the problem.
Assuming you’re using Colaboratory, with all your notebooks stored in a Google Drive folder named Colab Notebooks. Simply add the following two lines after you mount GDrive:

import sys
sys.path.append(root_dir + "Colab Notebooks/")

NOTE: root_dir referenced from the Google Colab server setup instructions.

Just copy the below code in a notebook cell and comment the line “from crappify import *”

from fastai.vision import *
from PIL import Image, ImageDraw, ImageFont

class crappifier(object):
    def __init__(self, path_lr, path_hr):
        self.path_lr = path_lr
        self.path_hr = path_hr              
        
    def __call__(self, fn, i):       
        dest = self.path_lr/fn.relative_to(self.path_hr)    
        dest.parent.mkdir(parents=True, exist_ok=True)
        img = PIL.Image.open(fn)
        targ_sz = resize_to(img, 96, use_min=True)
        img = img.resize(targ_sz, resample=PIL.Image.BILINEAR).convert('RGB')
        w,h = img.size
        q = random.randint(10,70)
        ImageDraw.Draw(img).text((random.randint(0,w//2),random.randint(0,h//2)), str(q), fill=(255,255,255))
        img.save(dest, quality=q)
1 Like