简体   繁体   English

ValueError:输入张量必须具有等级 4 TensorFlow

[英]ValueError: input tensor must have rank 4 TensorFlow

i am using fashion_mnist images database (60,000 small square 28×28 pixel grayscale images) and i am trying to apply CNN-LSTM in cascading, this is the code i am using:我正在使用 fashion_mnist 图像数据库(60,000 个小正方形 28×28 像素灰度图像),我正在尝试将 CNN-LSTM 应用于级联,这是我正在使用的代码:

from tensorflow.keras.datasets import fashion_mnist

(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()
print("Shape of x_train: {}".format(x_train.shape))
print("Shape of y_train: {}".format(y_train.shape))
print()
print("Shape of x_test: {}".format(x_test.shape))
print("Shape of y_test: {}".format(y_test.shape))

# define CNN model
model = Sequential()
model.add(TimeDistributed(Conv2D(32, kernel_size=(3, 3),
             activation='relu',
             input_shape=(60000,28,28))))
model.add(TimeDistributed(Conv2D(64, (3, 3), activation='relu')))
model.add(TimeDistributed(MaxPooling2D(pool_size=(2, 2))))
model.add(TimeDistributed((Dropout(0.25))))
model.add(TimeDistributed(Flatten()))

## LSTM
model.add(LSTM(200, activation='relu', return_sequences=True))
model.add(Dense(128, activation='relu'))
model.compile(loss='categorical_crossentropy', optimizer='adam',
          metrics=['accuracy'])

##fitting model
 model.fit(x_train,y_train,epochs=5)
 test_loss, test_acc=model.evaluate(x_test,y_test)
 print('Loss: {0}-Acc:{1}')

 print(test_acc)

i get the error after running the fitting line, can any one help me solving the error.运行拟合线后出现错误,任何人都可以帮我解决错误。

Define an Input layer with a four-channel output instead of defining the input with Conv2D layer.使用四通道 output 定义输入层,而不是使用 Conv2D 层定义输入。

暂无
暂无

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

相关问题 tensorflow-tf.confusion_matrix()引发错误ValueError:Shape(2,2048,2)必须具有等级2 - tensorflow - tf.confusion_matrix() throws error ValueError: Shape (2, 2048, 2) must have rank 2 TensorFlow 0.12教程产生警告:“输入Tensor的等级应与列的output_rank相同 - TensorFlow 0.12 tutorials produce warning: "Rank of input Tensor should be the same as output_rank for column PyTorch ValueError:目标和输入必须具有相同数量的元素 - PyTorch ValueError: Target and input must have the same number of elements ValueError:所有输入数组必须具有相同的形状 - ValueError: all input arrays must have the same shape ValueError:使用转换器 AutoTokenizer(MT5ForConditionalGerneration 模型)解码输入张量时,字节必须在范围 (0, 256) 内 - ValueError: bytes must be in range(0, 256) while decoding input tensor using transformer AutoTokenizer (MT5ForConditionalGerneration Model) ValueError: 输入到 `.fit()` 应该有 4 级。得到了形状的数组:(10, 20, 50, 50, 1) - ValueError: Input to `.fit()` should have rank 4. Got array with shape: (10, 20, 50, 50, 1) ValueError:形状必须至少为 3 级,但对于“{{node BiasAdd}} = BiasAdd[T=DT_FLOAT, data_format="NCHW"](add, bias)' 具有输入形状: - ValueError: Shape must be at least rank 3 but is rank 2 for '{{node BiasAdd}} = BiasAdd[T=DT_FLOAT, data_format="NCHW"](add, bias)' with input shapes: 尝试使用Caffe分类器会导致“序列参数的长度必须等于输入等级”错误 - Trying to to use Caffe classifier causes “sequence argument must have length equal to input rank ”error tensorflow Keras:维度必须相等 ValueError - tensorflow Keras: Dimenions must be equal ValueError ValueError:参数必须为密集张量:[[''1','2','3'],['1']]-形状为[2],但需要[2,3] - ValueError: Argument must be a dense tensor: [['1', '2', '3'], ['1']] - got shape [2], but wanted [2, 3]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM