View_classify in module 'helper'

I’m getting this error anytime I try using the module ‘helper’ to pass an image to the network.

module ‘helper’ has no attribute ‘view_classify’

What can I do about it?

1 Like

Where did you find the method view_classify?
It seems you are using some kind of wrapper (maybe from the Udacity course)?

1 Like

Yeah, Thank you. I got it resolved already.

how did you get it solved?
i am also getting the same error

Hey, can you tell me how you resolved this problem?
P.S. I already have helper.py file in ‘deep-learning-v2-pytorch-master\intro-to-pytorch’ folder.

[#Solution] Udacity Specifically
helper used here is not from pip but a .py file made by udacity, which is available in the repo
and view_classify is declared inside that.

The code is :

import matplotlib.pyplot as plt
import numpy as np

def view_classify(img, ps, version="MNIST"):
    ''' Function for viewing an image and it's predicted classes.
    '''
    ps = ps.data.numpy().squeeze()

    fig, (ax1, ax2) = plt.subplots(figsize=(6,9), ncols=2)
    ax1.imshow(img.resize_(1, 28, 28).numpy().squeeze())
    ax1.axis('off')
    ax2.barh(np.arange(10), ps)
    ax2.set_aspect(0.1)
    ax2.set_yticks(np.arange(10))
    if version == "MNIST":
        ax2.set_yticklabels(np.arange(10))
    elif version == "Fashion":
        ax2.set_yticklabels(['T-shirt/top',
                            'Trouser',
                            'Pullover',
                            'Dress',
                            'Coat',
                            'Sandal',
                            'Shirt',
                            'Sneaker',
                            'Bag',
                            'Ankle Boot'], size='small');
    ax2.set_title('Class Probability')
    ax2.set_xlim(0, 1.1)

plt.tight_layout()
6 Likes

Hi,

I had the same issue but solved it by importing all the notebooks (after cloning the repository) in Jupyter. If you want to see the images, you also have to create the ‘assets’ folder (in Jupyter) and then copy all the files from the asset folder in there.

I hope this helps.

2 Likes

Paste helper.py from the course folder into the folder where you are working and it should work

did the same see
still getting the error
https://gyazo.com/db7cdf213eafea306f97787fdd992b73
as you can see i have helper.py on the left

I can’t get it to work eventhough I change the path
( pls see the yellow color highlighted )

of course if I were to copy and paste the code in the same notebook it will work but I want to solve this issue of mine if it’s possible.

Thanks.

1 Like

Check the helper.py file and verify it has view_classify function.
And in case if it doesn’t, copy paste the same to helper.py
If it have, verify the function name.
The module is found, it’s just the function that is missing…

first, make sure that you have “helper.py” in the same directory
then choose restart runtime from the runtime

1 Like

in any code cell, run:

!wget https://raw.githubusercontent.com/udacity/deep-learning-v2-pytorch/3bd7dea850e936d8cb44adda8200e4e2b5d627e3/intro-to-pytorch/helper.py

Reload the page, restart runtime, and run all.

I coppied view_classify() function into the same file and still getting nothing. No error, just nothing happens. Once the network is done training - shell is just waiting for a new command. Can anybody help please?

Could you post the code which shows how you are calling this method?

I made it work in Jupyter Notebooks, maybe something is wrong with python on my computer