'TypeError: Inputs to a layer should be tensors. Got: <tensorflow.python.keras.engine.functional.Functional object at 0x000001ADE3B6BEE0>
I'm trying to Implement Inception_resnet_v2 inside Faster-RCNN instead of using ResNet50. but when I try to run the code I got this TypeError:
TypeError: Inputs to a layer should be tensors
and this is the code of inception_resnet_v2 inputs part: (only first & last few lines) N.B: if i only run InceptionResNetV2.py then i can see the model output perfectly.
def InceptionResNetV2(inputs):
img_input= inputs
#img_input = Input(shape=inputs)
#img_input = Input(shape=(600,600,3))
#img_input = Input(shape=input_shape)
# Stem block: 299,299,3 -> 35 x 35 x 192
x = conv2d_bn(img_input, 32, 3, strides=2, padding='valid')
x = conv2d_bn(x, 32, 3, padding='valid')
x = conv2d_bn(x, 64, 3)
x = MaxPooling2D(3, strides=2)(x)
x = conv2d_bn(x, 80, 1, padding='valid')
x = conv2d_bn(x, 192, 3, padding='valid')
x = MaxPooling2D(3, strides=2)(x)
.
.
.
.
x = Dense(6, activation='softmax', name='predictions')(x)
inputs = img_input
# model
x= Model(inputs, x, name='inception_resnet_v2')
return x
and this one is where I concat base_layers with Inception_resnet_v2(inputs)
def get_model(num_classes, backbone, num_anchors = 9):
#inputs = Input(shape=(600,600, 3))
inputs = Input(shape=(None, None, 3))
roi_input = Input(shape=(None, 4))
if backbone == 'inception_resnet_v2':
base_layers = InceptionResNetV2(inputs)
rpn = get_rpn(base_layers, num_anchors)
classifier = get_InceptionResNetV2_classifier(base_layers, roi_input, 14, num_classes)
Most probably i can't add base_layers with InceptionResNetV2(inputs).
I'll be very grateful if someone could help me out 🙏
Solution 1:[1]
First step is base_layers.output Then after your convolutional layer you need to reshape x so that it matches the shape expected, something like
#x = tf.reshape(x, shape =(q,im_size,im_size,3)) Where you have to find the right q to match the size expected.
I was doing the same, and got passed this one, but then I ran into:
INVALID_ARGUMENT: logits and labels must be broadcastable: logits_size=[5,5] labels_size=[20,5]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Odd Harald Auglend |