AirBernard / Scene-Text-Detection-with-SPCNET

Repository for Scene Text Detection with Supervised Pyramid Context Network with tensorflow.
120 stars 32 forks source link

ValueError: Dimensions must be equal, but are 32 and 256 for 'P5/TCM_Module/BroadcastTo' (op: 'BroadcastTo') with input shapes: [?,32,32], [4] and with input tensors computed as partial shapes: input[1] = [?,32,32,256]. #10

Open brooklyn1900 opened 5 years ago

brooklyn1900 commented 5 years ago

When I trained this model on cpu, it came an error: Dimensions must be equal, but are 32 and 256 for 'P5/TCM_Module/BroadcastTo' (op: 'BroadcastTo') with input shapes: [?,32,32], [4] and with input tensors computed as partial shapes: input[1] = [?,32,32,256].

What's the problem could it be? Thanks a lot!

brooklyn1900 commented 5 years ago

Solved it ! Solution in https://stackoverflow.com/questions/51982817/valueerror-dimensions-must-be-equal-but-are-4096-and-9-for-mul-why-no-broad?rq=1

Broadcasting in tensorflow follows the same patterns as NumPy broadcasting. When operating on two arrays, it compares their shapes element-wise, starting with the last dimension, and works its way to the first dimension. Two dimensions are compatible when:

they are equal, or
one of them is 1, or
one dimension is missing

In this case, starting from the last dimensions, the dimensions 4096 (the last dimension of the first array) and 9 (the last dimension of the second array) are not compatible according to the above rules, therefore giving you an error.

In order to fix it to get your desired broadcasting effect, you can transform the first array to have a compatible shape:

confidence_single_digit = tf.expand_dims(probs_L[:,1],1) * probs_S1

So that the shapes are (4096, 1) and (4096, 9) respectively.

So I add a line :

active = tf.expand_dims(active, -1) 

in nets/model.py in def TCM_module, before the line

_broadcast = tf.broadcast_to(active, tf.shape(input_feature))_