Categories
Development

Keras layer and Nonetype [on hold]

Edit 2:

Well, the problem in this case seems to be that, when creating a custom Keras layer, self.add_weight does not allow a Nonetype input. Keras’ own BatchNormalization function does not seem to allow Nonetype inputs either.

According to this article, this code should work; It should provide a functioning Faster RCNN. However, I cannot get past the FixedBatchNormalization error. Replacing it with Keras’ own BatchNormalization didn’t help either.

The desired effect, of course, is having a functioning Faster RCNN. However, I am not sure why this code initalizes the neural network with an empty tensor. I hoped someone here would know why that is the case.

So, I guess my current question is; Why would you start the neural network this way:

input_shape_img = (None, None, 3)

img_input = Input(shape=input_shape_img)

# define the base network (resnet here, can be VGG, Inception, etc)

shared_layers = nn.nn_base(img_input, trainable=True)

Batchnormalization is inside nn_base. That makes this whole thing crash because it cannot handle None. So, the code is completely unable to define the base network.


Edit:
It look like the problem lies in this class. I know this program is supposed to work. So, how do I need to adjust self.add_weight to allow Nonetype?


I am trying to understand this implementation of Faster RCNN. However, it is two years old, and probably a lot has changed since then. I am encountering one issue. The writer has on purpose made the input to the code below equal to

Tensor(“input_3:0”, shape=(?,?,?,3), dtype=float32)

However, the FixedBatchNormalization produces this error message:

TypeError: int() argument must be a string, a bytes-like object or a
number, not ‘NoneType’

    x = ZeroPadding2D((3, 3))(img_input)

    x = Convolution2D(64, (7, 7), strides=(2, 2), name='conv1', trainable = trainable)(x)
    x = FixedBatchNormalization(axis=bn_axis, name='bn_conv1')(x)
    x = Activation('relu')(x)
    x = MaxPooling2D((3, 3), strides=(2, 2))(x)

    x = conv_block(x, 3, [64, 64, 256], stage=2, block='a', strides=(1, 1), trainable = trainable)
    x = identity_block(x, 3, [64, 64, 256], stage=2, block='b', trainable = trainable)
    x = identity_block(x, 3, [64, 64, 256], stage=2, block='c', trainable = trainable)

    x = conv_block(x, 3, [128, 128, 512], stage=3, block='a', trainable = trainable)
    x = identity_block(x, 3, [128, 128, 512], stage=3, block='b', trainable = trainable)
    x = identity_block(x, 3, [128, 128, 512], stage=3, block='c', trainable = trainable)
    x = identity_block(x, 3, [128, 128, 512], stage=3, block='d', trainable = trainable)

    x = conv_block(x, 3, [256, 256, 1024], stage=4, block='a', trainable = trainable)
    x = identity_block(x, 3, [256, 256, 1024], stage=4, block='b', trainable = trainable)
    x = identity_block(x, 3, [256, 256, 1024], stage=4, block='c', trainable = trainable)
    x = identity_block(x, 3, [256, 256, 1024], stage=4, block='d', trainable = trainable)
    x = identity_block(x, 3, [256, 256, 1024], stage=4, block='e', trainable = trainable)
    x = identity_block(x, 3, [256, 256, 1024], stage=4, block='f', trainable = trainable)

How can I work around this? What has changed and why? This code was supposed to work…

The code is taken from the resnet.py file. It is in the nn_base function.

Leave a Reply

Your email address will not be published. Required fields are marked *