作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我正在为一类分类构建图像分类器,其中我在运行此模型时使用了自动编码器,但出现此错误(ValueError:使用不是符号张量的输入调用了层 conv2d_3。已收到类型:。完整输入:[(128, 128, 3)]。该层的所有输入都应该是张量。)
num_of_samples = img_data.shape[0]
labels = np.ones((num_of_samples,),dtype='int64')
labels[0:376]=0
names = ['cat']
Y = np_utils.to_categorical(labels, num_class)
input_shape=img_data[0].shape
x,y = shuffle(img_data,Y, random_state=2)
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=2)
x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_shape)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
encoded = MaxPooling2D((2, 2), padding='same')(x)
# at this point the representation is (4, 4, 8) i.e. 128-dimensional
x = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2, 2))(x)
x = Conv2D(16, (3, 3), activation='relu')(x)
x = UpSampling2D((2, 2))(x)
decoded = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)
autoencoder = Model(input_shape, decoded)
autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')
autoencoder.fit(X_train, X_train,
epochs=50,
batch_size=32,
shuffle=True,
validation_data=(X_test, X_test),
callbacks=[TensorBoard(log_dir='/tmp/autoencoder')])
最佳答案
这里:
x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_shape)
形状不是张量。
这样做:
from keras.layers import *
inputTensor = Input(input_shape)
x = Conv2D(16, (3, 3), activation='relu', padding='same')(inputTensor)
您应该将编码器和解码器分离为单独的模型。稍后您可能只想使用其中一个。
编码器:
inputTensor = Input(input_shape)
x = ....
encodedData = MaxPooling2D((2, 2), padding='same')(x)
encoderModel = Model(inputTensor,encodedData)
解码器:
encodedInput = Input((4,4,8))
x = ....
decodedData = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)
decoderModel = Model(encodedInput,decodedData)
自动编码器:
autoencoderInput = Input(input_shape)
encoded = encoderModel(autoencoderInput)
decoded = decoderModel(encoded)
autoencoderModel = Model(autoencoderInput,decoded)
关于keras - 使用非符号张量的输入调用层 conv2d_3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47822154/
我正在尝试从以下路径中提取一组关键字,例如 ['lemon', 'apple', 'coconut'] 等"\var\prj\lemon_123\xyz","\var\prj\123_apple\co
每次当我尝试连接到发送 servage smpt 时,它都会给我一个错误: SMTP connect() failed. 我尝试以下设置: include('res/mailer/class.phpm
我正在尝试通过 cpanel cron 作业面板提交 MySQL 备份脚本,但我收到了我不理解的错误。我已经在我的 Ubuntu 上尝试了这个命令 mysqldump -u(USERNAME) -p(
我喜欢将测试程序的输出记录到带有时间戳的日志文件中。 我创建了以下 Makefile,但它不起作用。 “make”似乎在最后一刻根据需要计算 LOGFILE。 生成文件 LOGFILE=`date +
我是一名优秀的程序员,十分优秀!