現在、Unetを再作成しようとしています。 2つのレイヤーの出力をマージする必要がある「アップコンボリューション」の部分で、前述のエラーが発生しました。 (TypeError:init()は引数 'axis'に複数の値を取得しました)
コードスニペット:
import gzip
import os
from six.moves import urllib
import tensorflow as tf
import numpy as np
from keras.models import Sequential, Model
from keras.layers import Input, Dropout, Flatten, Concatenate
from keras.layers import Conv2D, MaxPool2D, Conv2DTranspose
from keras.utils import np_utils
import keras.callbacks
# Define model architecture
input1 = Input((X_train.shape[1], X_train.shape[2], 1))
conv1 = Conv2D(64,(3,3), activation='relu', padding='same')(input1)
conv1 = Dropout(0.2)(conv1)
conv1 = Conv2D(64,(3,3), activation='relu', padding='same')(conv1)
pool1 = MaxPool2D(pool_size=(2,2))(conv1)
conv2 = Conv2D(128,(3,3), activation='relu', padding='same')(pool1)
conv2 = Dropout(0.2)(conv2)
conv2 = Conv2D(128,(3,3), activation='relu')(conv2)
pool2 = MaxPool2D(pool_size=(2,2))(conv2)
conv3 = Conv2D(256,(3,3), activation='relu', padding='same')(pool2)
conv3 = Dropout(0.2)(conv3)
conv3 = Conv2D(256,(3,3), activation='relu', padding='same')(conv3)
pool3 = MaxPool2D(pool_size=(2,2))(conv3)
conv4 = Conv2D(512,(3,3), activation='relu', padding='same')(pool3)
conv4 = Conv2D(512,(3,3), activation='relu', padding='same')(conv4)
up5 = Concatenate([Conv2DTranspose(256, (2,2), strides=(2,2),padding='same')(conv4), conv3], axis=3)
conv5 = Conv2D(256,(3,3), activation='relu', padding='same')(up5)
conv5 = Conv2D(256,(3,3), activation='relu', padding='same')(conv5)
詳細なエラーメッセージ:
Traceback (most recent call last):
File "<ipython-input-48-d61955511ff9>", line 1, in <module>
runfile('C:/Users/.../MNIST_Unet_new.py', wdir='C:/Users/.../Documents/KerasTutorials')
File "C:\ProgramData\Anaconda3\envs\tensorflow-gpu\lib\site-packages\spyder\utils\site\sitecustomize.py", line 688, in runfile
execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\envs\tensorflow-gpu\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/.../MNIST_Unet_new.py", line 107, in <module>
up5 = Concatenate([Conv2DTranspose(256, (2,2), strides=(2,2),padding='same')(conv4), conv3], axis=3)
TypeError: __init__() got multiple values for argument 'axis'
連結はケラの層であり、その使用は
keras.layers.Concatenate(axis=-1)
ここで、concatenateの代わりにConcatenateを使用する場合は、次のように使用する必要があります。
up5 = Concatenate(axis=3)([Conv2DTranspose(256, (2,2), strides=(2,2),padding='same')(conv4), conv3])
お役に立てば幸いです。