VahidooX / DeepCCA

An implementation of Deep Canonical Correlation Analysis (DCCA or Deep CCA) with Keras.
MIT License
246 stars 77 forks source link

create_model raises error AttributeError: 'Tensor' object has no attribute 'T' #3

Closed fredyjl closed 7 years ago

fredyjl commented 7 years ago

the function create_model raises error when evaluating customized cca objective: model = create_model(layer_sizes1, layer_sizes2, input_shape1, input_shape2, learning_rate, reg_par, outdim_size, use_all_singular_values) results in errors AttributeError: 'Tensor' object has no attribute 'T'. Below is the complete error message: `--------------------------------------------------------------------------- AttributeError Traceback (most recent call last)

in () 38 # Building, training, and producing the new features by DCCA 39 model = create_model(layer_sizes1, layer_sizes2, input_shape1, input_shape2, ---> 40 learning_rate, reg_par, outdim_size, use_all_singular_values) 41 model.summary() 42 #model = train_model(model, data1, data2, epoch_num, batch_size) ~/Downloads/DeepCCA-master/models.py in create_model(layer_sizes1, layer_sizes2, input_size1, input_size2, learning_rate, reg_par, outdim_size, use_all_singular_values) 20 21 model_optimizer = RMSprop(lr=learning_rate) ---> 22 model.compile(loss=cca_loss(outdim_size, use_all_singular_values), optimizer=model_optimizer) 23 24 return model ~/anaconda2/envs/dcca/lib/python3.5/site-packages/keras/models.py in compile(self, optimizer, loss, metrics, sample_weight_mode, weighted_metrics, **kwargs) 782 sample_weight_mode=sample_weight_mode, 783 weighted_metrics=weighted_metrics, --> 784 **kwargs) 785 self.optimizer = self.model.optimizer 786 self.loss = self.model.loss ~/anaconda2/envs/dcca/lib/python3.5/site-packages/keras/engine/training.py in compile(self, optimizer, loss, metrics, loss_weights, sample_weight_mode, weighted_metrics, target_tensors, **kwargs) 848 with K.name_scope(self.output_names[i] + '_loss'): 849 output_loss = weighted_loss(y_true, y_pred, --> 850 sample_weight, mask) 851 if len(self.outputs) > 1: 852 self.metrics_tensors.append(output_loss) ~/anaconda2/envs/dcca/lib/python3.5/site-packages/keras/engine/training.py in weighted(y_true, y_pred, weights, mask) 448 """ 449 # score_array has ndim >= 2 --> 450 score_array = fn(y_true, y_pred) 451 if mask is not None: 452 # Cast the mask to floatX to avoid float64 upcasting in theano ~/Downloads/DeepCCA-master/objectives.py in inner_cca_objective(y_true, y_pred) 20 21 # unpack (separate) the output of networks for view 1 and view 2 ---> 22 H1 = y_pred[:, 0:o1].T 23 H2 = y_pred[:, o1:o1+o2].T 24 AttributeError: 'Tensor' object has no attribute 'T' `
fredyjl commented 7 years ago

Oops, turns out I forgot to switch to theano backend. Easy fix.

swathi-vennela commented 3 years ago

Can you please share, how you fixed this error

gongshuai0606 commented 1 year ago

How did you fix it?