2017-10-09 47 views
0

我使用python3在我的jupyter的tensorflow教程中运行此代码,并且出现以下错误;应用于图像上的卷积 - TypeError:'Variable'对象不可调用

#Importing 
import numpy as np 
from scipy import signal 
from scipy import misc 
import matplotlib.pyplot as plt 
from PIL import Image  

### Load image of your choice on the notebook 
print("Please type the name of your test image after uploading to \ 
your notebook (just drag and grop for upload. Please remember to \ 
type the extension of the file. Default: bird.jpg") 

raw = input() 
im = Image.open(raw) # type here your image's name 

# uses the ITU-R 601-2 Luma transform (there are several ways to convert an 
# image to grey scale) 

image_gr = im.convert("L")  
print("\n Original type: %r \n\n" % image_gr) 

# convert image to a matrix with values from 0 to 255 (uint8) 
arr = np.asarray(image_gr) 
print("After conversion to numerical representation: \n\n %r" % arr) 
### Activating matplotlib for Ipython 
%matplotlib inline 

### Plot image 
imgplot = plt.imshow(arr) 
imgplot.set_cmap('gray') 
print("\n Input image converted to gray scale: \n") 
plt.show(imgplot) 


Please type the name of your test image after uploading to your notebook 
(just drag and grop for upload. Please remember to type the extension of the file. Default: bird.jpg 

TypeError         Traceback (most recent call last) 
<ipython-input-26-061778a3dd36> in <module>() 
    14 print("Please type the name of your test image after uploading to 
your notebook (just drag and grop for upload. Please remember to type the 
extension of the file. Default: bird.jpg") 
    15 
---> 16 raw = input() 
    17 
    18 

类型错误:“变量”对象不是可调用

我试图寻找此类型错误,但没有准确地指定为“变量”对象。感谢你的帮助。

+0

该错误表明您已经有一个名为'input'的变量。你是在iPython还是其他一些IDE中运行它,在那里有一个名为'input'的变量?尝试将脚本缩减到较小的部分,以查看什么是休息和什么可行。 – charlesreid1

+0

我用jupyter笔记本运行此代码。 raw_input()首先被使用,但是有一个未定义名称的错误。然后我把它改为input(),正如python3所建议的那样。 – Nat

回答

-1

我刚刚发现这个由修复@tacaswell

https://stackoverflow.com/a/31687067/7468989

只需添加本线;

from six.moves import input 
+0

目前还不清楚它是如何解决原始文章中描述的问题的 - 如果在调用input()函数时在Python 3中发生问题,那么从6导入input()将不会实质性地改变任何内容。您发布的代码与导致错误的代码之间是否存在不一致? – charlesreid1

+0

我在代码中改变的唯一的事情是从“raw_input()”,我得到一个未定义名称的错误,以“input()”为上面指定的错误。 – Nat