Pytorch_Retinaface icon indicating copy to clipboard operation
Pytorch_Retinaface copied to clipboard

whats the retinaface of resnet50 input shape?

Open DDFlyInCode opened this issue 6 years ago • 10 comments
trafficstars

whats the retinaface of resnet50 input shape?

DDFlyInCode avatar Oct 22 '19 07:10 DDFlyInCode

When training, input is cropped to 840*840 defined in "data/config.py".

biubug6 avatar Oct 22 '19 07:10 biubug6

how about inference?

DDFlyInCode avatar Oct 22 '19 08:10 DDFlyInCode

i found inference code can recevied any inputshape image. This may lead some problems in model convert when I use onnx. Because onnx model is base on static map ,can not auto resize with mutil size image. I dont know what to do ! Looking forward to help , thx. By the way! Your project is amazing

DDFlyInCode avatar Oct 22 '19 09:10 DDFlyInCode

When testing, I provide original image size as input in widerface val. You can scale image to a certain size according to the effect and your needs. See "test_widerface.py" for details.

biubug6 avatar Oct 22 '19 09:10 biubug6

Because of the full convolution structure of network, It don't lead some problems in model convert when I convert model from onnx to NCNN and deploy the model.

biubug6 avatar Oct 23 '19 01:10 biubug6

Ultimately the model still prefers its training dimensions, but it will work at any resolution. You should set the size based on the minimum face size you desire.

xsacha avatar Oct 29 '19 13:10 xsacha

I thought that onnx supports dynamic input sizes now, from: https://pytorch.org/tutorials/advanced/super_resolution_with_onnxruntime.html "Note that the input size will be fixed in the exported ONNX graph for all the input’s dimensions, unless specified as a dynamic axes" Making input fixed makes results worse for datasets with differently sized images (like Widerface). Did anyone tried onnx version with dynamic input sizes?

SnowRipple avatar Nov 05 '19 13:11 SnowRipple

PyTorch 1.2 supports dynamic input now, such as:

model = models.resnet18() dummy_input = torch.zeros(1, 3, 224, 224) inputs = ['images'] outputs = ['scores'] dynamic_axes = {'images': {0: 'batch'}, 'scores': {0: 'batch'}} torch.onnx.export(model, dummy_input, 'test.onnx', input_names=inputs, output_names=outputs, dynamic_axes=dynamic_axes)

SnowRipple avatar Nov 05 '19 13:11 SnowRipple

Because of the full convolution structure of network, It don't lead some problems in model convert when I convert model from onnx to NCNN and deploy the model.

can you share your demo how to load onnx model ,please? thank you

121649982 avatar Jan 07 '20 11:01 121649982

For people who have trouble in exporting to onnx model with arbitrary height and width, You can do the following way:

model.eval()

# Define the input and output names for the ONNX model
input_names = ["input"]
output_names = ["output"]

# Export the PyTorch model to ONNX format
output_path = "retinaface.onnx"

batch_size = 1 # random initialization
dummy_input = torch.randn(batch_size, 3, 640, 640) # This is a random tensor with the same shape as the expected input
dynamic_axes = {'input' : {2 : 'height', 3:'width'}, # enables the model to accept dynamic batch sizes
                }

torch.onnx.export(model, dummy_input.to(device), output_path,
                  do_constant_folding=True,
                  input_names=input_names, output_names=output_names,
                  dynamic_axes=dynamic_axes)

The ONNX model can now accept images of any input size just like pytorch. And you don't have to worry about resizing the input images. Just follow the pre- and post-processing steps in detect.py

venki-lfc avatar Aug 21 '23 14:08 venki-lfc