Tianxiaomo / pytorch-YOLOv4

PyTorch ,ONNX and TensorRT implementation of YOLOv4
Apache License 2.0
4.48k stars 1.49k forks source link

convalution havn't activate linear #370

Open piperod opened 3 years ago

piperod commented 3 years ago

I am getting this warning error, even though I am using the default cfg for yolov4. not sure if this is crucial for performance. According to the metric provided AP is very very low. What should be the right activation? Should I change something else? I am training on a custom dataset.

MattiaMolon commented 3 years ago

I was also wondering what this warning was referring to. It seems like the linear activations are skipped during the construction of the model in: https://github.com/Tianxiaomo/pytorch-YOLOv4/blob/4ccef0ec8fe984e059378813e33b3740929e0c19/tool/darknet2pytorch.py#L261-L268

I am wondering if this is an error or not. If the activation in the yolo.cfg file is linear, shouldn't we do something like this?

else:
       model.add_module(("linear{0}".format(conv_id), nn.Linear(filters, filters, bias=False)))

Let me know if you managed to solve this

Huxwell commented 3 years ago

I am experiencing huge difference in scores (activations, 'confidence', 'probabilities') per bounding box when comparing original darknet detections with detections after onnx conversion. Wondering if this might be the reason. @MattiaMolon @piperod has the solution above worked well for you?

To me it results in RuntimeError: mat1 and mat2 shapes cannot be multiplied (924x80 and 21x21)

Huxwell commented 3 years ago

Ok, the solution seems to be using nn.Identity (a placeholder that essentialy does nothing, but still keep values in the computation graph).

The code:

                elif activation == 'linear':
                    model.add_module("linear{0}".format(conv_id), nn.Identity(filters, filters, bias=False))
                # based on https://github.com/Tianxiaomo/pytorch-YOLOv4/issues/370
                else:
                    print("convalution haven't activate {}".format(activation))

Based on: https://github.com/pjreddie/darknet/blob/master/src/activations.h static inline float linear_activate(float x){return x;} https://pytorch.org/docs/stable/nn.html: nn.Identity - A placeholder identity operator that is argument-insensitive. nn.Linear - Applies a linear transformation to the incoming data: y = xA^T + by=xAT+b

@Tianxiaomo please review the pr: https://github.com/Tianxiaomo/pytorch-YOLOv4/pull/412