gpt4 book ai didi

python - 用于考虑 keras 最后一层网络的训练

转载 作者:行者123 更新时间:2023-11-30 09:16:48 24 4
gpt4 key购买 nike

这是我的模型代码:

Model=Sequential()
input_img = Input(shape=(180,180,3)) # adapt this if using channels_first` image data format


x = Conv2D(64, (3, 3), padding='valid')(input_img)

x = Conv2D(64, (3, 3), padding='valid',strides=2)(x)
x = BatchNormalization()(x)
x = Activation('relu')(x)

y = Conv2D(64, (3, 3), padding='valid')(x)
model=Model(input_img,y)

生成器部分如下所示

train_datagen = ImageDataGenerator(rescale=1./255)


test_datagen = ImageDataGenerator(rescale=1./255)


train_generator=train_datagen.flow_from_directory(
'\Dipti\medical_image_comp',
target_size=(180,180),
batch_size=128,
class_mode=None)

validation_generator = test_datagen.flow_from_directory(
'D:\Dipti\medical_image_comp\scale0',
target_size=(180,180),
batch_size=128,
class_mode=None)

通过以下方式拟合这个简单的网络:

history=model.fit_generator(
train_generator,
epochs=100,
steps_per_epoch=training_samples/batch_size,
validation_data=validation_generator,
validation_steps=testing_samples/batch_size)

The following error occurs:

纪元 1/100

   ValueError                                Traceback (most recent 
call last)
<ipython-input-41-bf2c0dd3bbcf> in <module>()
4 epochs=100,
5 validation_data=validation_generator,

- ---> 6 valid_steps=testing_samples/batch_size)

  ~\Anaconda3\lib\site-packages\keras\legacy\interfaces.py in 
wrapper(*args, **kwargs)
89 warnings.warn('Update your `' + object_name +
90 '` call to the Keras 2 API: ' + signature, stacklevel=2)

- --> 91 return func(*args, **kwargs) 92 包装器._original_function = func 93 返回包装器

~\Anaconda3\lib\site-packages\keras\models.py in fit_generator(self、generator、steps_per_epoch、epochs、verbose、callbacks、validation_data、validation_steps、class_weight、max_queue_size、workers、use_multiprocessing、shuffle、initial_epoch) 第1254章 第1255章-> 1256 初始纪元 = 初始纪元) 第1257章 第1258章

~\Anaconda3\lib\site-packages\keras\legacy\interfaces.py 包装器(*args, **kwargs) 89 warnings.warn('更新您的 ' + object_name +
90 '
调用 Keras 2 API:' + 签名,stacklevel=2) ---> 91 返回 func(*args, **kwargs) 92 包装器._original_function = func 93 返回包装器

  ~\Anaconda3\lib\site-packages\keras\engine\training.py in 
fit_generator(self, generator, steps_per_epoch, epochs, verbose,
callbacks, validation_data, validation_steps, class_weight,
max_queue_size, workers, use_multiprocessing, shuffle,
initial_epoch)
2160 'a tuple `(x,
y, sample_weight)` '
2161 'or `(x,
y)`. Found: ' +
-> 2162
str(generator_output))
2163 # build batch logs
2164 batch_logs = {}

ValueError: Output of generator should be a tuple `(x, y,
sample_weight)` or `(x, y)`. Found: [[[[1.
0.91372555 1. ]
[0.8980393 0.78823537 0.87843144]
[0.8705883 0.7607844 0.85098046]
...
[0.8313726 0.7411765 0.8117648 ]
[0.85098046 0.7607844 0.8313726 ]
[0.83921576 0.7490196 0.8196079 ]]

[[0.9333334 0.8352942 0.9215687 ]
[0.8980393 0.8000001 0.8862746 ]
[0.9294118 0.8313726 0.9176471 ]
...
[0.7803922 0.6901961 0.7607844 ]
[0.8196079 0.7294118 0.8000001 ]
[0.8588236 0.7686275 0.83921576]]

[[0.9176471 0.8235295 0.909804 ]
[0.854902 0.7607844 0.8470589 ]
[0.8745099 0.7803922 0.86666673]
...
[0.7686275 0.6784314 0.7490196 ]
[0.79215693 0.7019608 0.7725491 ]
[0.83921576 0.7490196 0.8196079 ]]

...

[[0.81568635 0.6784314 0.7725491 ]
[0.80392164 0.6666667 0.7607844 ]
[0.8196079 0.68235296 0.77647066]
...
[0.8470589 0.6784314 0.78823537]
[0.8352942 0.6666667 0.77647066]
[0.8745099 0.7058824 0.81568635]]

[[0.7686275 0.6313726 0.7254902 ]
[0.7607844 0.62352943 0.7176471 ]
[0.79215693 0.654902 0.7490196 ]
...
[0.8431373 0.6745098 0.7843138 ]
[0.83921576 0.67058825 0.7803922 ]
[0.882353 0.7137255 0.8235295 ]]

[[0.8235295 0.6862745 0.7725491 ]
[0.7725491 0.63529414 0.72156864]
[0.78823537 0.6509804 0.74509805]
...
[0.8588236 0.6901961 0.8000001 ]
[0.86666673 0.69803923 0.8078432 ]
[0.8862746 0.7176471 0.82745105]]]


[[[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
...
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]]

[[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
...
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]]

[[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
...
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]]

...

[[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
...
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]]

[[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
...
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]]

[[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
...
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]
[0.8705883 0.8705883 0.8705883 ]]]


[[[0.92549026 0.82745105 0.90196085]
[0.89019614 0.7843138 0.8588236 ]
[0.9176471 0.8078432 0.8941177 ]
...
[0.7960785 0.47450984 0.6627451 ]
[0.76470596 0.43529415 0.627451 ]
[0.77647066 0.44705886 0.6392157 ]]

[[0.9058824 0.8000001 0.8745099 ]
[0.8941177 0.7803922 0.8588236 ]
[0.86666673 0.7411765 0.8313726 ]
...
[0.80392164 0.48235297 0.67058825]
[0.79215693 0.47058827 0.65882355]
[0.8588236 0.5294118 0.72156864]]

[[0.83921576 0.7254902 0.80392164]
[0.87843144 0.75294125 0.8352942 ]
[0.8235295 0.6901961 0.7843138 ]
...
[0.8078432 0.48627454 0.6745098 ]
[0.80392164 0.48235297 0.67058825]
[0.8862746 0.5647059 0.75294125]]

...

我无法得到这样一个简单的网络。我已经建立了很多具有相同概念的模型,但是这里这个网络无法训练。请建议我如何训练这样一个简单的网络流程来自使用 Adam 优化器和 MSE 作为损失函数的目录概念。我希望你能明白我的意思

先生,通过这个小型网络,我只是想减小图像的大小,训练该网络后,我必须将该网络的输出应用于图像编解码器,并进一步执行相反的过程来生成重建的图像然后出于测试目的,我必须比较原始图像和比较图像。因为这基本上是一个压缩任务,减小图像的大小,所以特别是我的工作不需要标签,就像分类和回归的情况一样。我想要复制标题为“使用卷积神经网络的端到端压缩框架”的论文的结果,而这个小网络基本上是我想使用其参数进行训练的第一个模块。您还可以检查纸张我希望你现在理解整个问题了

最佳答案

可能在您的生成器中,您将标签作为元组的第一个元素返回,并将输入图像作为第二个元素返回。交换这两个,问题就解决了。

关于python - 用于考虑 keras 最后一层网络的训练,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53871779/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com