【问题标题】:Theano TypeErrorTheano 类型错误
【发布时间】:2016-01-12 16:22:03
【问题描述】:

我正在阅读 jpg 图像,然后将它们重塑为张量。我将图像投射为 float32:

def load(folder,table):
X=[]

train = pd.read_csv(table)

for i,img_id in enumerate(train['Image']):

    img = io.imread(folder+img_id[2:])

    X.append(img)

X = np.array(X)/255.
X = X.astype(np.float32)
X = X.reshape(-1, 1, 225, 225)
return X

但是,我收到了这个错误

TypeError: ('Bad input argument to theano function with name "/Users/mas/PycharmProjects/Whale/nolearn_convnet/Zahraa5/lib/python2.7/site-packages/nolearn/lasagne/base.py:435"  at index 1(0-based)', 'TensorType(int32, vector) cannot store a value of dtype float32 without risking loss of precision. If you do not mind this loss, you can: 1) explicitly cast your data to int32, or 2) set "allow_input_downcast=True" when calling "function".', array([[ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       ..., 
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],

       [ 0.,  0.,  0., ...,  0.,  0.,  0.]], dtype=float32))

【问题讨论】:

    标签: numpy theano lasagne nolearn


    【解决方案1】:

    这是cross-post to the theano-users mailing list

    Doug 在那里提供了答案:

    你使用的 theano 变量被定义为整数,但是你 传入一个浮点数,因此错误'TensorType(int32,vector)不能 存储 dtype float32...' 的值。您可以修改您的数据 加载代码以将其转换为 int32,或将符号变量更改为 支持 float32 的东西。

    所以在某处你有一条看起来像这样的线:

    x = T.ivector()
    

    x = T.vector(dtype='int32')
    

    看来您需要将其更改为类似

    x = T.tensor4()
    

    其中dtype 已更改为等于theano.config.floatX,并且维度已更改为 4 以匹配 X 的 4 维性质。

    【讨论】:

    • 有问题的变量是代码中描述的 X。我的意思是张量一个 4D 变量颠簸数组。 @DanielRenshaw
    • 对 theano-users 邮件列表的回复。
    【解决方案2】:

    如果您没有弄明白,我遇到了类似的错误,这是我修复它的方法: 将您的 y 转换为 int32。 x 值可以是 floatx,但在 nolearn 中 y 必须是 int32 才能进行分类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-19
      • 2014-05-19
      • 1970-01-01
      • 1970-01-01
      • 2018-04-08
      • 1970-01-01
      • 2016-02-03
      • 2018-08-15
      相关资源
      最近更新 更多