简体   繁体   English

ValueError:“顺序”层的输入 0 与该层不兼容:预期形状=(无,256、256、3),找到的形状=(无,33)

[英]ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 256, 256, 3), found shape=(None, 33)

I started running dukkakc's code about DeepSuccinySite and i have a problem.我开始运行 dukkakc 关于 DeepSuccinySite 的代码,但我遇到了问题。 The result show: ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 256, 256, 3), found shape=(None, 33).结果显示:ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 256, 256, 3), found shape=(None, 33)。 I've been searching for the error for a long time but to no avail.我一直在寻找错误很长时间但无济于事。 Can someone help me?有人能帮我吗?

from tensorflow import keras
import numpy as np
from Bio import SeqIO
from numpy import array
from imblearn.under_sampling import RandomUnderSampler
from sklearn.utils import shuffle
from sklearn.metrics import roc_curve, auc, classification_report
from keras.models import load_model

r_test_x = []
r_test_y = []
posit_1 = 1;
negat_0 = 0;
win_size = 33 # actual window size
win_size_kernel = int(win_size/2 + 1)

# define universe of possible input values
alphabet = 'ARNDCQEGHILKMFPSTWYV-'
# define a mapping of chars to integers
char_to_int = dict((c, i) for i, c in enumerate(alphabet))
int_to_char = dict((i, c) for i, c in enumerate(alphabet))

#-------------------------TEST DATASET----------------------------------------
#for positive sequence
def innertest1():
#Input
data = seq_record.seq
#rint(data) 
# integer encode input data
for char in data:
    if char not in alphabet:
        return
integer_encoded = [char_to_int[char] for char in data]
r_test_x.append(integer_encoded)
r_test_y.append(posit_1)
for seq_record in SeqIO.parse("test_positive_sites.fasta", "fasta"):
innertest1()
#for negative sequence
def innertest2():
#Input
data = seq_record.seq
#print(data) 
# integer encode input data
for char in data:
    if char not in alphabet:
        return
integer_encoded = [char_to_int[char] for char in data]
r_test_x.append(integer_encoded)
r_test_y.append(negat_0)
for seq_record in SeqIO.parse("test_negative_sites.fasta", "fasta"):
innertest2()
# Changing to array (matrix)    
r_test_x = array(r_test_x)
r_test_y = array(r_test_y)

# Balancing test dataset
# Testing Data Balancing by undersampling####################################
rus = RandomUnderSampler(random_state=7)
x_res3, y_res3 = rus.fit_resample(r_test_x, r_test_y)
#Shuffling
r_test_x, r_test_y = shuffle(x_res3, y_res3, random_state=7)
r_test_x = np.array(r_test_x)
r_test_y = np.array(r_test_y)
############################################################################

##LOAD MODEL####
model = load_model('model.h5')
#print("This is final ",model.layers[0].get_weights()[0][16])
r_test_y_2 = keras.utils.to_categorical(r_test_y, 2)
score = model.evaluate(r_test_x, r_test_y_2, verbose=0)
print('Test loss:', score[0])
print('Test accuracy:', score[1])

from sklearn.metrics import matthews_corrcoef
from sklearn.metrics import confusion_matrix
Y_pred = model.predict(r_test_x)
Y_pred = (Y_pred > 0.5)
y_pred1 = [np.argmax(y, axis=None, out=None) for y in Y_pred]
y_pred1 = np.array(y_pred1)

print("Matthews Correlation : ",matthews_corrcoef(r_test_y, y_pred1))
print("Confusion Matrix : \n",confusion_matrix(r_test_y, y_pred1))
# ROC

fpr, tpr, _ = roc_curve(r_test_y, y_pred1)
roc_auc = auc(fpr, tpr)
print("AUC : ", roc_auc)
print(classification_report(r_test_y, y_pred1))

print(model.summary())

Your input has to match the expected format of the input layer of your model. You can use reshape to get the right format, expected the dimension match, otherwise you'll need to pad the missing dimensions.您的输入必须与 model 输入层的预期格式相匹配。您可以使用reshape来获得正确的格式,预期尺寸匹配,否则您需要填充缺失的尺寸。

import numpy as np

A = np.random.rand(16,1,1)
A.shape
  (16,1,1)

B = A.reshape([4,4,1,1]
B.shape
  (4,4,1,1)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError: 层“sequential_2”的输入 0 与层不兼容:预期形状=(None, 256, 256, 3),发现形状=(None, 1, 256, 256, 3) - ValueError: Input 0 of layer "sequential_2" is incompatible with the layer: expected shape=(None, 256, 256, 3), found shape=(None, 1, 256, 256, 3) Keras LSTM ValueError:层“顺序”的输入 0 与层不兼容:预期形状 =(无,478405,33),找到形状 =(1、33) - Keras LSTM ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 478405, 33), found shape=(1, 33) ValueError:layersequential_1 的输入 0 与 layer 不兼容::预期 min_ndim=4,发现 ndim=3。 收到的完整形状:[无、256、256] - ValueError: Input 0 of layer sequential_1 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 256, 256] ValueError:layersequential_32 的输入 0 与 layer 不兼容::预期 min_ndim=3,发现 ndim=2。 收到的完整形状:[无,256] - ValueError: Input 0 of layer sequential_32 is incompatible with the layer: : expected min_ndim=3, found ndim=2. Full shape received: [None, 256] ValueError:层 sequential_3 的输入 0 与层不兼容::预期 min_ndim=4,发现 ndim=3。 已收到完整形状:(无、224、256) - ValueError: Input 0 of layer sequential_3 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (None, 224, 256) 层“sequential_14”的输入 0 与层不兼容:预期形状=(None, 256, 256, 3),找到的形状=(None, 32, 32, 3) - nput 0 of layer "sequential_14" is incompatible with the layer: expected shape=(None, 256, 256, 3), found shape=(None, 32, 32, 3) ValueError:“顺序”层的输入 0 与该层不兼容:预期形状 =(None, 60, 5),找到的形状 =(None, 60, 7) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 60, 5), found shape=(None, 60, 7) ValueError:“顺序”层的输入 0 与层不兼容:预期形状 =(无,223461,5),找到形状 =(无,5) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 223461, 5), found shape=(None, 5) ValueError: 层“sequential_1”的输入 0 与层不兼容:预期形状=(None, 60, 1),发现形状=(None, 59, 1) - ValueError: Input 0 of layer "sequential_1" is incompatible with the layer: expected shape=(None, 60, 1), found shape=(None, 59, 1) ValueError:层“顺序”的输入0与层不兼容:预期形状=(无,90),发现形状=(无,2,90) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 90), found shape=(None, 2, 90)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM