我正在使用colab并已经!pip install helper,但是我遇到错误AttributeError:模块'helper'没有属性'imshow'并且 AttributeError:模块“ helper”没有属性“ view_classify” 助手有什么问题?
答案 0 :(得分:0)
如果您获得AttributeError
,则表明您已安装helper
,但版本不同。
您可以只用一点点呼叫来开始Colab笔记本
!pip install helper==x.y.z
...
并且每次启动新的运行时都需要运行它。
答案 1 :(得分:0)
您所指的帮助程序库由Udacity开发。
定义imshow函数,如下所示:
def imshow(image, ax=None, title=None, normalize=True):
"""Imshow for Tensor."""
if ax is None:
fig, ax = plt.subplots()
image = image.numpy().transpose((1, 2, 0))
if normalize:
mean = np.array([0.485, 0.456, 0.406])
std = np.array([0.229, 0.224, 0.225])
image = std * image + mean
image = np.clip(image, 0, 1)
ax.imshow(image)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.tick_params(axis='both', length=0)
ax.set_xticklabels('')
ax.set_yticklabels('')
return ax
随后致电:
imshow(“您的图片”);
你很好!
参考:
https://github.com/udacity/DL_PyTorch/blob/master/helper.py#L42
答案 2 :(得分:0)
要解决这些问题,请在笔记本的最上方运行以下代码以安装帮助文件;
!wget -c https://raw.githubusercontent.com/udacity/deep-learning-v2-pytorch/master/intro-to-pytorch/helper.py
然后重新启动笔记本计算机的整个运行时,以加载文件
答案 3 :(得分:0)
安装:
!wget https://raw.githubusercontent.com/udacity/deep-learning-v2-pytorch/3bd7dea850e936d8cb44adda8200e4e2b5d627e3/intro-to-pytorch/helper.py
然后:
import importlib <br>
importlib.reload(helper)
答案 4 :(得分:-1)
从udacity复制并粘贴view_classify
函数,然后使用它。
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)