0

I am implementing object detection using faster-RCNN Getting error:

ValueError: Input 0 is incompatible with layer res5a_branch2a: expected ndim=4, found ndim=5

for below network design

num_rois=4
roi_input = Input(shape=(num_rois, 4))
out_roi_pool = RoiPoolingConv(14, 3)([model2.output, roi_input])

reference RoiPoolingConv is user-defined function and output of out_roi_pool

<tf.Tensor 'roi_pooling_conv_49/transpose:0' shape=(1, 3, 14, 14, 2048) 
dtype=float32>


pooling_regions = 14 #Size of pooling region
num_rois=4           #number of regions of interest
input_shape = (num_rois,14,14,1024)
nb_filter1, nb_filter2, nb_filter3 = [512,512,2048]
old_layer = TimeDistributed(Convolution2D(nb_filter1, (1, 1), strides=(1,1), 
trainable=False, kernel_initializer='normal'),input_shape=out_roi_pool.shape, name='2b')(out_roi_pool )

Refered question link but still not able to resolved error.

source TimeDistributed Any leads much appreciated..!!

devesh
  • 618
  • 6
  • 26

2 Answers2

1

you can add dense layer at end of your base model

i.e. model2.output before giving directly to RoiPoolingConv function

 x = Dense(1024, name='avg_pool')(model2.layers[-1].output)
 in_img = model2.input
 new_model = Model(input=in_img, output=[x])
 new_model.summary()
 out_roi_pool = RoiPoolingConv(14, 3)([new_model.output, roi_input])

Or you have build model put input shape accordingly as did github project

sparken
  • 11
  • 2
0

Posting the answer to resolve error for people who may or will stuck in dimension mismatch error

num_rois=4
roi_input = Input(shape=(num_rois, 4))
out_roi_pool = RoiPoolingConv(14, 3)([model2.output, roi_input])

RoiPoolingConv is user-defined function and redefine output of out_roi_pool Now output will be

<tf.Tensor 'roi_pooling_conv_49/transpose:0' shape=(1, 3, 14, 14,1024) dtype=float32>
pooling_regions = 14 #Size of pooling region
num_rois=4           #number of regions of interest
input_shape = (num_rois,14,14,1024)
nb_filter1, nb_filter2, nb_filter3 = [512,512,1024]
old_layer = TimeDistributed(Convolution2D(nb_filter1, (1, 1), strides=(1,1), 
trainable=False, 
kernel_initializer='normal'),input_shape=out_roi_pool.shape, name='2b') 
(out_roi_pool )

This resolved my error

devesh
  • 618
  • 6
  • 26