ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.65k stars 16.33k forks source link

Use activation function #584

Closed phucnhs closed 4 years ago

phucnhs commented 4 years ago

❔Question

Hi ! How to use activation function FRELU,MISH....in source code ? Thanks !

Additional context

github-actions[bot] commented 4 years ago

Hello @phucnhs, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook Open In Colab, Docker Image, and Google Cloud Quickstart Guide for example environments.

If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom model or data training question, please note Ultralytics does not provide free personal support. As a leader in vision ML and AI, we do offer professional consulting, from simple expert advice up to delivery of fully customized, end-to-end production solutions for our clients, such as:

For more information please visit https://www.ultralytics.com.

glenn-jocher commented 4 years ago

@phucnhs you can replace existing activations in any of the default modules in models/common.py or models/experimental.py. Most modules use common.Conv(), which is our basic lower level convolutional module. Replacing the LeakyReLU() activation here will have the greatest effect on YOLOv5 models. You can always print(model) to see the effects of your changes.

https://github.com/ultralytics/yolov5/blob/48e15be498ab6f3335743b5df7fbd02edd068160/models/common.py#L18-L28

phucnhs commented 4 years ago

Thanks bro ! I see try and close issues !

PariaDarbani commented 3 years ago

I changed the common.py to self.act = nn.ReLU() if act is True else (act if isinstance(act, nn.Module) else nn.Identity()) but there is no change in print(model): ... (act): SiLU(inplace=True) ...

but when I change "SiLU" in yolov5.pt then print(model): ... (act): ReLU(inplace=True) ...

glenn-jocher commented 3 years ago

@PariaDarbani activation functions can be modified here for training custom models: https://github.com/ultralytics/yolov5/blob/306fc0119a94915b91fb6ca6f46f2d50437152e3/models/common.py#L43

PariaDarbani commented 3 years ago

@PariaDarbani activation functions can be modified here for training custom models: https://github.com/ultralytics/yolov5/blob/306fc0119a94915b91fb6ca6f46f2d50437152e3/models/common.py#L43

I am using inference mode, not training. I want to change the activation function (SiLU) to ReLU for pre-trained yolov5s. I changed the common.py but it doesn't work.

glenn-jocher commented 3 years ago

@PariaDarbani you never change a model at inference time, you use a fully trained model.

You can modify a model before training starts.