I am currently trying to recreate the Unet. At the "upconvolution" part where the outputs of two layers needs to be merged I got the mentioned error. (TypeError: init() got multiple values for argument 'axis')
Code snippet:
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)
Detailed error message:
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'
I have found a solution that seems to work!
I have done two changes to the code.
The relevant code snippet now looks like this
trans5 = Conv2DTranspose(256, (2,2), strides=(2,2),padding='same')(conv4)
up5 = keras.layers.concatenate([trans5, conv3], axis=3)
Might this be some kind of bug in keras? Should I report that issue?
Thanks so much for your help anyway. Appreciate it!
I was also getting error like this.
up5_0 = Concatenate([UpSampling2D(size=(2, 2))(conv4_0), conv4], axis=3)
TypeError: __init__() got multiple values for argument 'axis'
I solved it using just concatenate
instead of Concatenate
up5_0 = concatenate([UpSampling2D(size=(2, 2))(conv4_0), conv4], axis=3)
Concatenate is a layer of keras,the use of it is
keras.layers.Concatenate(axis=-1)
Here if you want to use Concatenate instead of concatenate.you should use like this:
up5 = Concatenate(axis=3)([Conv2DTranspose(256, (2,2), strides=(2,2),padding='same')(conv4), conv3])
Hope useful for you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With