Tensorflow InvalidArgumentError:发现2个根错误。(0)无效参数:矩阵大小不兼容:在[0]:[665,64],在[1]:[42560,1]

Tensorflow InvalidArgumentError:发现2个根错误。(0)无效参数:矩阵大小不兼容:在[0]:[665,64],在[1]:[42560,1],tensorflow,matrix,keras,reshape,predict,Tensorflow,Matrix,Keras,Reshape,Predict,[[{node densite_22/MatMul}][[densite_23/Sigmoid/_329]](1)无效参数:矩阵大小不兼容:在[0]:[665,64],在[1]:[42560,1] 这一切都属于:y_分数=model.predict(X_测试,verbose=1,batch_size=256) 欢迎使用SO。从错误中,我们可以预测您的模型和输入形状之间存在不兼容。为了准确查找错误产生的位置,请提供以下内容:(i)您的模型代码,(2)您的输入形状。stackoverflow团队不允

[[{node densite_22/MatMul}][[densite_23/Sigmoid/_329]](1)无效参数:矩阵大小不兼容:在[0]:[665,64],在[1]:[42560,1]
这一切都属于:y_分数=model.predict(X_测试,verbose=1,batch_size=256)


欢迎使用SO。从错误中,我们可以预测您的模型和输入形状之间存在不兼容。为了准确查找错误产生的位置,请提供以下内容:(i)您的模型代码,(2)您的输入形状。stackoverflow团队不允许提供详细信息。他们指出了这个错误,这个错误我已经很厌倦了纠正。他们正在失去智能性#!pip install git+import tensorflow as tf tf.compat.v1.disable_v2;_behavior()从未来导入打印功能中,分区导入numpy作为np导入h5py导入scipy.io导入随机导入系统,操作系统导入ITERTOOL从集合导入计数器导入编号
from warnings import warn
from abc import ABCMeta, abstractmethod
from tensorflow import keras, reshape
np.random.seed(1337)  # for reproducibility
import keras
from keras.optimizers import RMSprop, SGD
from keras.models import Sequential, model_from_yaml
from keras.layers.core import Dense, Dropout, Activation, Flatten
import keras.layers.core as core
from keras.layers import Dense, Dropout, Embedding, LSTM, Input, merge, multiply, Reshape
from keras.layers.convolutional import Convolution1D, MaxPooling1D
from keras.layers.wrappers import Bidirectional
from keras.constraints import maxnorm
from keras.layers.recurrent import LSTM, GRU
from keras.callbacks import ModelCheckpoint, EarlyStopping
from keras.layers import Embedding
from sklearn.metrics import fbeta_score, roc_curve, auc, roc_auc_score, average_precision_score
import matplotlib.pyplot as plt
from keras.regularizers import l2, l1, l1_l2
# from keras.models import Model
from tensorflow.keras.models import Model 
# from keras import backend as K
import tensorflow.keras.backend as K
from keras.engine.topology import Layer
from keras import activations, initializers, regularizers, constraints
from keras.engine import InputSpec

from keras.layers import ActivityRegularization
class Attention(Layer):
    def __init__(self,hidden,init='glorot_uniform',activation='linear',W_regularizer=None,b_regularizer=None,W_constraint=None,**kwargs):
      self.init = initializers.get(init)
      self.activation = activations.get(activation)
      self.W_regularizer = regularizers.get(W_regularizer)
      self.b_regularizer = regularizers.get(b_regularizer)
      self.W_constraint = constraints.get(W_constraint)
      self.hidden=hidden
      super(Attention, self).__init__(**kwargs)
    def build(self, input_shape):
      input_dim = input_shape[-1]
      self.input_length = input_shape[1]
      self.W0 = self.add_weight(name ='{}_W1'.format(self.name), shape = (input_dim, self.hidden), initializer = 'glorot_uniform', trainable=True) # Keras 2 API
      self.W  = self.add_weight( name ='{}_W'.format(self.name),  shape = (self.hidden, 1), initializer = 'glorot_uniform', trainable=True)
      self.b0 = K.zeros((self.hidden,), name='{}_b0'.format(self.name))
      self.b  = K.zeros((1,), name='{}_b'.format(self.name))

      print (modil.summary())
      return modil
      #for Testing only

def test(n_estimators = 16):
        model = set_up_model_up()
       
        X_test = np.load('/content/drive/MyDrive/X_test.npy', mmap_mode='r')
        y_test = np.load('/content/drive/MyDrive/y_test.npy', mmap_mode='r')
        ensemble = np.zeros(len(X_test))
        for i in range(n_estimators):
           print ('testing', i, 'model')
           print ('model shape is', model.summary)
           model.load_weights('/content/drive/MyDrive/model/bestmodel_split_chr_GD_'+ str(i) + '.hdf5')
           print ('model shape after loading is', model.summary)
           #Once the model is created, you can config the model with losses and metrics with model.compile(), train the model with model.fit(), or use the model to do prediction with model.predict().
           print ('Predicting...')
           #  X_test=X_test.Reshape(665,-1)
           print ('testing',X_test.shape)
           print (len(model.layers))
           #  y_score = model.predict(np.expand_dims(np.array(X_test, dtype=np.float32), 0), verbose = 1, batch_size = 256)
           
           formatmul= np.empty((3,2000,4), dtype=object)
           for x in range(0, 2):
             for y in range(0, 1999):
               for z in range(0, 3):
                 formatmul[x][y][z]=X_test[x][y][z]
           y_score = model.predict(X_test).reshape(665,-1), verbose = 1, batch_size = 256)
           print("model.output_shape",model.output_shape)
           print("model.input_shape",model.input_shape)
            y_score = model.predict(formatmul, batch_size=42560)
           y_score = model.predict(np.array(formatmul, dtype=np.float32), batch_size =665)
           y_pred = []
        for item in y_score:
           y_pred.append(item[0])
           y_pred =  np.array(y_pred)
           ensemble += y_pred
        ensemble /= n_estimators
        np.save('/content/drive/MyDrive/test_result/y_test', y_test)
        np.save('/content/drive/MyDrive/test_result/y_pred', ensemble)
        auroc = roc_auc_score(y_test, ensemble)
        aupr  = average_precision_score(y_test, ensemble)
        print ('auroc', auroc)
        print ('aupr' , aupr)

test(n_estimators = 16)