0

I am trying to build a custom CNN using keras functional API. The issue with my theoretical idea and pratical one is that when I try to Average the ouput of three Conv2D layers and pass it to another Conv2D. I get an error saying that the output of Average is tf.float meanwhile Conv2D (that is the first convolution layer of VGG16, because I am doing transfer learning) expects to get a tf.int32

I am getting the follwing error: **TypeError: Expected int32, got 0.0 of type 'float' instead.

Notes:

  1. I have tried Maximum and Minimum as a test only and still getting the same error.
  2. Unfortunetly I can't share the code because of NDA.

Here's a code snippet:

self._layer_hs_o = Average(name="heads")(
      [self._layer_hs_s, self._layer_hs_m, self._layer_hs_l])
# Trying to pass the average output to the following Conv2D layer
self._layer_d2c_c = Conv2D(d2c_config["filters"], 
      d2c_config["kernels"][0], 
      padding="same",
      activation=d2c_config["activation"], 
      name="d2c_c",
      kernel_initializer=d2c_config["init"],
      input_shape=self._layer_hs_o.shape,
      dilation_rate=d2c_config["dilations"][0]
    )(self._layer_hs_o)

At this moment the model can't be compiled because of this step. When I skip it to normal convolutions only it get compiled and the learning happens normally. Yet I need to use the Average layer at some extent.

haddagart
  • 68
  • 1
  • 8
  • Please add reproducible code. – Innat Nov 27 '21 at 09:28
  • @M.Innat Sadly, I can't add reproducible code because the project that I am working on requires non disclosure agreement. I am bound to some legal concerns. – haddagart Nov 27 '21 at 09:54
  • No, I didn't want you to do that. I simply requested to give some reproducible code (with some dummy data). FYI, while averaging the output of the layer, I think you can change the type of average layer to `int`. – Innat Nov 27 '21 at 10:07
  • We cannot help you unless you share some code that reproduces or shows the problem, as this error makes no sense to me. – Dr. Snoopy Nov 27 '21 at 10:09
  • @M.Innat I've added a snippet of my code please check it. Thank you for your help in advance. – haddagart Nov 27 '21 at 10:26

0 Answers0