0

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.

3
  • Does this answer your question? TypeError: __array__() takes 1 positional argument but 2 were given (Image classification Keras) Commented Jul 11, 2021 at 11:21
  • @Kaveh no unfortunately sir, could you please help me countryman? thank you very much Commented Jul 11, 2021 at 12:13
  • This error is because of this line y[:,r,c] = tensor[:,i,j,h]. Left side is a list, and the right side is a tensor. You should use something like tf.slice and tf.stack or tf.concat to 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. Commented Jul 11, 2021 at 18:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.