The expanded size of the tensor must match the existing size at non-singleton dimension

ngap_wei_Tham: <p>Trying to quantize the object detection model of <a href="https://github.com/sacmehta/EdgeNets" rel="nofollow noopener">EdgeNet2</a> but fail, using the pretrained model from <a href="https://github.com/sacmehta/EdgeNets/blob/master/model/detection/model_zoo/README.md" rel="nofollow noopener">here</a>(ms coco 300x300).</p>
<pre><code>    qconfig = torch.quantization.get_default_qconfig('qnnpack')
    print(qconfig)		
    model.eval()
    model.qconfig = qconfig
    torch.quantization.prepare(model, inplace=True)		        
	
    predictor = BoxPredictor(cfg=cfg, device=device)
    #works fine if I do not run the main_images
    main_images(predictor=predictor, model=model, object_names=object_names,
                in_dir=args.im_dir, out_dir=args.save_dir, device=device)
	
    # Convert to quantized model
    torch.quantization.convert(model, inplace=True)
    torch.save(model.state_dict(), "espnet2v_300.pt")        		
    print("save as quantize model")		       


def main_images(predictor, model, object_names, in_dir, out_dir, device='cuda'):
    png_file_names = glob.glob(in_dir + os.sep + '*.png')
    jpg_file_names = glob.glob(in_dir + os.sep + '*.jpg')
    file_names = png_file_names + jpg_file_names

    if len(file_names) == 0:
        print_error_message('No image files in the folder')

    # model in eval mode
    model.eval()
    with torch.no_grad():
        for img_name in file_names:
            image = cv2.imread(img_name)
            predictor.predict(model, image, is_scaling=False)                
</code></pre>
<p>If I do not run the main_images function, I can quantize the model, If I  run the main_images function, I received error message.</p>
<p><strong>The expanded size of the tensor (243076) must match the existing size (262144) at non-singleton dimension 0.  Target sizes: [243076].  Tensor sizes: [262144]</strong></p>
<p>The main_images function works fine if I do not quantize it, any idea how should I fix this?Or do anyone know an object detection project of pytorch suit for quantization? Thanks</p>
<p>ps : Tried with the model of tflite, but accuracy is not that good.</p>

ptrblck: <p>Based on the error message it seems you might be passing the wrong input shape.<br>
Is this error specific to the quantization module, i.e. is it running fine without quantization?<br>
Could you try to resize the <code>image</code> array to the expected shape?</p>

ngap_wei_Tham: <aside class="quote no-group" data-username="ptrblck" data-post="2" data-topic="82566">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p>is it running fine without quantization?</p>
</blockquote>
</aside>
<p>Yes, totally fine.</p>
<aside class="quote no-group" data-username="ptrblck" data-post="2" data-topic="82566">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p>Could you try to resize the <code>image</code> array to the expected shape?</p>
</blockquote>
</aside>
<p>Already do that, it works before quantize</p>