I am trying to execute this code,
lyr_in = Input(shape=(400, 400, 3))
# Block 1
lyr = Conv2D(filters=4, kernel_size=(1, 1), padding='same', activation='relu')(lyr_in)
lyr = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(lyr)
# Block 2
lyr = Conv2D(filters=8, kernel_size=(1, 1), padding='same', activation='relu')(lyr)
lyr = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(lyr)
# Block 3
lyr = Conv2D(filters=8, kernel_size=(1, 1), padding='same', activation='relu')(lyr)
# Block 4
lyr = Conv2D(filters=16, kernel_size=(1, 1), padding='same', activation='relu')(lyr)
# Block 5
lyr = Conv2D(filters=16, kernel_size=(1, 1), padding='same', activation='relu')(lyr)
lyr = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(lyr)
# Block 6
lyr = Conv2D(filters=256, kernel_size=(1, 1), padding='same', activation='relu')(lyr)
lyr = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(lyr)
def custom_layer(tensor):
y = np.zeros((64,400, 400))
for i in range(0, 25):
for j in range(0, 25):
r = 16 * I
h = 0
for m in range(0, 16):
c = 16 * j
for n in range(0, 16):
y[:,r,c] = tensor[:,i,j,h]
c = c + 1
h = h + 1
r = r + 1
return y
lyr_out = Lambda(custom_layer, name="lambda_layer", output_shape=(400,400))(lyr)
#lyr_out = Reshape((400, 400))(lambda_layer)
M1 = Model(lyr_in, lyr_out)
print(M1.summary())
I'm a beginner in Keras and TensorFlow, I want to rearrange the pixel of images in Keras model by a custom layer by lambda layer but i interface this bellow error;
TypeError: __array__() takes 1 positional argument but 2 were given
how can i fix it friends? thank you very very much.
y[:,r,c] = tensor[:,i,j,h]. Left side is a list, and the right side is a tensor. You should use something liketf.sliceandtf.stackortf.concatto do such operation. However, I recommend to explain what do you want to do in your custom layer, then people may suggest a good way to do so.