google / qkeras

QKeras: a quantization deep learning library for Tensorflow Keras
Apache License 2.0
538 stars 104 forks source link

QConv1D error #2

Closed linbaiwpi closed 4 years ago

linbaiwpi commented 5 years ago

hello, I tried QConv1D in the following way

def Test_quant(bit_width):
    input_points = Input(shape=((32,32)))
    g = QConv1D(64, 1,
                kernel_quantizer=quantized_bits(bit_width,0,1),
                bias_quantizer=quantized_bits(bit_width,0,1),
                name="conv1")(input_points)

    model = Model(inputs=input_points, outputs=g)

    return model

net = Test_quant(8)
net.summary()

But get error as bellow:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~\Anaconda3\envs\tf36\lib\site-packages\tensorflow\python\framework\tensor_shape.py in merge_with(self, other)
    670       try:
--> 671         self.assert_same_rank(other)
    672         new_dims = []

~\Anaconda3\envs\tf36\lib\site-packages\tensorflow\python\framework\tensor_shape.py in assert_same_rank(self, other)
    715         raise ValueError("Shapes %s and %s must have the same rank" % (self,
--> 716                                                                        other))
    717 

ValueError: Shapes (1, 1) and (?,) must have the same rank

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
~\Anaconda3\envs\tf36\lib\site-packages\tensorflow\python\framework\tensor_shape.py in with_rank(self, rank)
    745     try:
--> 746       return self.merge_with(unknown_shape(ndims=rank))
    747     except ValueError:

~\Anaconda3\envs\tf36\lib\site-packages\tensorflow\python\framework\tensor_shape.py in merge_with(self, other)
    676       except ValueError:
--> 677         raise ValueError("Shapes %s and %s are not compatible" % (self, other))
    678 

ValueError: Shapes (1, 1) and (?,) are not compatible

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
~\Anaconda3\envs\tf36\lib\site-packages\tensorflow\python\ops\nn_ops.py in __init__(self, input_shape, dilation_rate, padding, build_op, filter_shape, spatial_dims, data_format)
    396     try:
--> 397       rate_shape = dilation_rate.get_shape().with_rank(1)
    398     except ValueError:

~\Anaconda3\envs\tf36\lib\site-packages\tensorflow\python\framework\tensor_shape.py in with_rank(self, rank)
    747     except ValueError:
--> 748       raise ValueError("Shape %s must have rank %d" % (self, rank))
    749 

ValueError: Shape (1, 1) must have rank 1

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-57-fdfe4b11dc04> in <module>
     10     return model
     11 
---> 12 net = Test_quant(8)
     13 net.summary()

<ipython-input-57-fdfe4b11dc04> in Test_quant(bit_width)
      4                 kernel_quantizer=quantized_bits(bit_width,0,1),
      5                 bias_quantizer=quantized_bits(bit_width,0,1),
----> 6                 name="conv1")(input_points)
      7 
      8     model = Model(inputs=input_points, outputs=g)

~\Anaconda3\envs\tf36\lib\site-packages\keras\engine\base_layer.py in __call__(self, inputs, **kwargs)
    455             # Actually call the layer,
    456             # collecting output(s), mask(s), and shape(s).
--> 457             output = self.call(inputs, **kwargs)
    458             output_mask = self.compute_mask(inputs, previous_mask)
    459 

~\Desktop\quantization\PointNet-Keras\qkeras\qlayers.py in call(self, inputs)
   1014         padding=self.padding,
   1015         data_format=self.data_format,
-> 1016         dilation_rate=self.dilation_rate)
   1017 
   1018     if self.use_bias:

~\Anaconda3\envs\tf36\lib\site-packages\keras\backend\tensorflow_backend.py in conv1d(x, kernel, strides, padding, data_format, dilation_rate)
   3609         strides=(strides,),
   3610         padding=padding,
-> 3611         data_format=tf_data_format)
   3612 
   3613     if data_format == 'channels_first' and tf_data_format == 'NWC':

~\Anaconda3\envs\tf36\lib\site-packages\tensorflow\python\ops\nn_ops.py in convolution(input, filter, padding, strides, dilation_rate, name, data_format)
    777         dilation_rate=dilation_rate,
    778         name=name,
--> 779         data_format=data_format)
    780     return op(input, filter)
    781 

~\Anaconda3\envs\tf36\lib\site-packages\tensorflow\python\ops\nn_ops.py in __init__(self, input_shape, filter_shape, padding, strides, dilation_rate, name, data_format)
    854         filter_shape=filter_shape,
    855         spatial_dims=spatial_dims,
--> 856         data_format=data_format)
    857 
    858   def _build_op(self, _, padding):

~\Anaconda3\envs\tf36\lib\site-packages\tensorflow\python\ops\nn_ops.py in __init__(self, input_shape, dilation_rate, padding, build_op, filter_shape, spatial_dims, data_format)
    397       rate_shape = dilation_rate.get_shape().with_rank(1)
    398     except ValueError:
--> 399       raise ValueError("rate must be rank 1")
    400 
    401     if not dilation_rate.get_shape().is_fully_defined():

ValueError: rate must be rank 1

My Keras version is 2.24 and Tensorflow version is 1.12.0

Guyume commented 4 years ago

hi @linbaiwpi , Did you solve this problem ? I meet the same. can use qconv2d to instead of qconv1d to make it work?

nunescoelho commented 4 years ago

We solved the problem. We are packaging a release with this fix early next week.

Claudionor

On Thu, Nov 28, 2019, 4:37 AM Guyume notifications@github.com wrote:

hi @linbaiwpi https://github.com/linbaiwpi , Did you solve this problem ? I meet the same. can use qconv2d to instead of qconv1d to make it work?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/google/qkeras/issues/2?email_source=notifications&email_token=AM5ENPEFLVCFZS3B2QZCJNTQV63P3A5CNFSM4JADWTYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFMPP6Y#issuecomment-559478779, or unsubscribe https://github.com/notifications/unsubscribe-auth/AM5ENPHWMP2M46OUWGINVSLQV63P3ANCNFSM4JADWTYA .

zhuangh commented 4 years ago

We will push the fix and close this issue then. thanks!

zhuangh commented 4 years ago

Thank you all for reporting this! We pushed the fix and close this issue. Feel free to reopen if you have further questions or bugs.