2016-01-12 28 views
1

我讀的JPG圖片,然後重塑他們到一個張量。我鑄造的圖像作爲FLOAT32:Theano類型錯誤

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)) 

回答

1

這是一個cross-post to the theano-users mailing list

道格提供有一個答案:

您所使用的theano變量被定義爲整數,但你 通過在浮子,因此錯誤「TensorType(INT32,載體)不能 存儲的值的dtype float32 ...'。您可以修改數據 加載代碼,以強制轉換爲INT32,或象徵性的變量更改爲 一些支持FLOAT32。

所以某處你有一條線,看起來像:

x = T.ivector() 

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

它看起來像你需要這個更改爲類似

x = T.tensor4() 

dtype已被更改d等於theano.config.floatX並且維度被改變爲4以匹配X的四維性質。

+0

問題變量是X,如代碼中所述。我的意思是張量4D可變顛簸陣列。 @DanielRenshaw – MAS

+0

對theano-users郵件列表的回覆。 –

1

如果你沒有弄明白,我有一個類似的錯誤,這裏是我如何修復它: 鑄造你的y作爲int32。 x值可以是floatx,但是y必須是int32以便分類。