Open DDFlyInCode opened 5 years ago
When training, input is cropped to 840*840 defined in "data/config.py".
how about inference?
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
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.
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.
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.
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?
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)
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
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
whats the retinaface of resnet50 input shape?