2016-05-05 5 views
1

thisfile.py型マッチングエラー[タイプTensorTypeに(可変<Generic>の)タイプのジェネリックを変換できません]

import cPickle 
import gzip 
import os 
import numpy 

import theano 
import theano.tensor as T 

def load_data(dataset): 
    f = gzip.open(dataset, 'rb') 
    train_set, valid_set, test_set = cPickle.load(f) 
    f.close() 


    def shared_dataset(data_xy, borrow=True): 
     data_x, data_y = data_xy 
     shared_x = theano.shared(numpy.asarray(data_x, 
               dtype=theano.config.floatX), 
           borrow=borrow) 
     shared_y = theano.shared(numpy.asarray(data_y, 
               dtype=theano.config.floatX), 
           borrow=borrow) 
     return shared_x, T.cast(shared_y, 'int32') 

    test_set_x, test_set_y = shared_dataset(test_set) 
    valid_set_x, valid_set_y = shared_dataset(valid_set) 
    train_set_x, train_set_y = shared_dataset(train_set) 

    rval = [(train_set_x, train_set_y), (valid_set_x, valid_set_y), 
      (test_set_x, test_set_y)] 
    return rval 

class PCA(object): 

    def __init__(self): 
     self.param = 0  

    def dimemsion_transform(self, X): 
     m_mean = T.mean(X, axis=0) 
     X = X - m_mean   ##################### this line makes error 
     return X 

if __name__ == '__main__': 
    dataset = 'mnist.pkl.gz' 
    # load the MNIST data 
    data = load_data(dataset) 

    X = T.matrix('X') 

    m_pca = PCA() 

    transform = theano.function(
     inputs=[], 
     outputs=m_pca.dimemsion_transform(X), 
     givens={ 
      X: data 
     } 
    ) 

Traceback (most recent call last): 
    File ".../thisfile.py", line 101, in <module> 
    X: data 
    File ".../Theano/theano/compile/function.py", line 322, in function 
    output_keys=output_keys) 
    File ".../Theano/theano/compile/pfunc.py", line 443, in pfunc 
    no_default_updates=no_default_updates) 
    File ".../Theano/theano/compile/pfunc.py", line 219, in rebuild_collect_shared 
    cloned_v = clone_v_get_shared_updates(v, copy_inputs_over) 
    File ".../Theano/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates 
    clone_v_get_shared_updates(i, copy_inputs_over) 
    File ".../Theano/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates 
    clone_v_get_shared_updates(i, copy_inputs_over) 
    File ".../Theano/theano/compile/pfunc.py", line 93, in clone_v_get_shared_updates 
    clone_v_get_shared_updates(i, copy_inputs_over) 
    File ".../Theano/theano/compile/pfunc.py", line 96, in clone_v_get_shared_updates 
    [clone_d[i] for i in owner.inputs], strict=rebuild_strict) 
    File ".../Theano/theano/gof/graph.py", line 242, in clone_with_new_inputs 
    new_inputs[i] = curr.type.filter_variable(new) 
    File ".../Theano/theano/tensor/type.py", line 234, in filter_variable 
    self=self)) 
TypeError: Cannot convert Type Generic (of Variable <Generic>) into Type TensorType(float64, matrix). You can try to manually convert <Generic> into a TensorType(float64, matrix). 

以下のように示すエラー私はtheanoでPCA機能を作っています問題があります。 平均値は、それが、私はそれを修正しますどのように一致するエラーを入力与え、なぜ

私は取得しないPCAクラスにdimension_transformにMNISTデータから減算される

あなたの問題は、これらの行から来て

答えて

0

data = load_data(dataset) 

ここでdataはリストです(これがload_data()から返されます)。

transform = theano.function(
    inputs=[], 
    outputs=m_pca.dimemsion_transform(X), 
    givens={ 
     X: data 
    } 
) 

ここで値と​​して渡します。

[(train_set_x, train_set_y), (valid_set_x, valid_set_y), 
     (test_set_x, test_set_y)] = load_data(dataset) 

をしてから

givens={ 
     X: train_set_x 
    } 

または他の値のいずれかを使用します。あなたはそうのような)LOAD_DATAの戻り値(から希望の項目を抽出する必要があります。

関連する問題