简体   繁体   English

使用 keras 输出图像 - 如何为输出层指定形状。 输入图像和输出图像尺寸为(210,210,3)

[英]Output Image Using keras - how to specify shape for output layer. Input Image and Output Image Dimensions are(210,210,3)

I am new to Keras.我是 Keras 的新手。 I am trying to feed a color inverted image into a neural network and then predict the real image.我试图将彩色反转图像输入神经网络,然后预测真实图像。 So that my x becomes the inverted image and y becomes the real image.这样我的 x 变成了倒像,y 变成了真实的图像。 But I am not knowing how to get an output image with keras.但我不知道如何使用 keras 获取输出图像。

这就是我想要表演的

Here is my code.这是我的代码。

import numpy as np
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
from keras.models import Sequential
from keras.layers import Conv2D,MaxPooling2D,Flatten,Dense

real=[]
for i in range(1,11):
    img=load_img(f"resized 1/{i}.jpg",target_size=(210,200))
    img=img_to_array(img)
    real.append(img)

invs=[]
for i in range(1,11):
    img=load_img(f"resized 2/{i}i.jpg",target_size=(210,200))
    img=img_to_array(img)
    invs.append(img)

x=np.array(invs)
y=np.array(real)
x=x/255
y=y/255


model=Sequential()

model.add(Conv2D(64,(3,3),activation='relu'))
model.add(MaxPooling2D((2,2)))

model.add(Conv2D(64,(3,3),activation='relu'))
model.add(MaxPooling2D((2,2)))

model.add(Flatten())
model.add(Dense(128,input_shape=x.shape[1:],activation='relu'))

what should i do after this how should i specify the output layer....I'm stuck在此之后我应该怎么做我应该如何指定输出层....我被卡住了

model.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])
model.fit(x,y,epochs=5,validation_split=0.1)

Thanks in advance.... I have referred this post but cant get anything - Keras: feed images into CNN and get image output在此先感谢.... 我已经提到了这篇文章,但什么也得不到 - Keras:将图像输入 CNN 并获得图像输出

This is not a classification or regression problem.这不是分类或回归问题。 Thus, the type of neural network that you are using (Convolutional) is not suitable for this problem.因此,您使用的神经网络类型(卷积)不适合此问题。

I think neural style transfer would be more appropriate.我认为神经风格转移会更合适。 In this case Generative Adversarial Network (GAN) should be used.在这种情况下,应该使用生成对抗网络 (GAN)。
You can read example about it here: https://www.tensorflow.org/tutorials/generative/dcgan您可以在此处阅读有关它的示例: https : //www.tensorflow.org/tutorials/generative/dcgan

After doing research in GANs.This problem is suitable for Pix2Pix GAN.在对GANs做了研究之后。这个问题适用于Pix2Pix GAN。

https://machinelearningmastery.com/how-to-implement-pix2pix-gan-models-from-scratch-with-keras/ https://machinelearningmastery.com/how-to-implement-pix2pix-gan-models-from-scratch-with-keras/

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM