Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix config activation passing to SPPBottleneck #161

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

adamp87
Copy link

@adamp87 adamp87 commented Mar 15, 2025

Bugfix: the SPPBottleneck in all three tinynas implementation is missing the passing of the activation function defined in the config file. This PR fixes it. See export of training logs at bottom.

This PR adds ReLU6 to ops.py as selectable activation function. Furthermore, it fixes the visualization for demo.py, as OpenCV fails with readonly numpy arrays. See, opencv/opencv#24522. This fixes #138 and obsoletes #160

Training log, branch main

        (5): SuperResStem(
          (act): ReLU6(inplace=True)
          (block_list): ModuleList(
            (0): MobileV3Block(
              (conv): Sequential(
                (0): Conv2d(160, 1760, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (1): SyncBatchNorm(1760, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)
                (2): ReLU6(inplace=True)
                (3): Conv2d(1760, 1760, kernel_size=(5, 5), stride=(2, 2), padding=(2, 2), groups=1760, bias=False)
                (4): SyncBatchNorm(1760, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)
                (5): Identity()
                (6): ReLU6(inplace=True)
                (7): Conv2d(1760, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (8): SyncBatchNorm(320, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)
              )
            )
            (1): SPPBottleneck(
              (conv1): ConvBNAct(
                (conv): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (bn): SyncBatchNorm(160, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)
                (act): SiLU(inplace=True) # BUG: activation not passed
              )
              (m): ModuleList(
                (0): MaxPool2d(kernel_size=5, stride=1, padding=2, dilation=1, ceil_mode=False)
                (1): MaxPool2d(kernel_size=9, stride=1, padding=4, dilation=1, ceil_mode=False)
                (2): MaxPool2d(kernel_size=13, stride=1, padding=6, dilation=1, ceil_mode=False)
              )
              (conv2): ConvBNAct(
                (conv): Conv2d(640, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (bn): SyncBatchNorm(320, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)
                (act): SiLU(inplace=True) # BUG: activation not passed
              )
            )
            (2): MobileV3Block(
              (conv): Sequential(
                (0): Conv2d(320, 1760, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (1): SyncBatchNorm(1760, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)
                (2): ReLU6(inplace=True)
                (3): Conv2d(1760, 1760, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), groups=1760, bias=False)
                (4): SyncBatchNorm(1760, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)
                (5): Identity()
                (6): ReLU6(inplace=True)
                (7): Conv2d(1760, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (8): SyncBatchNorm(320, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)
              )
            )
          )
        )

Training log, this PR

        (5): SuperResStem(
          (act): ReLU6(inplace=True)
          (block_list): ModuleList(
            (0): MobileV3Block(
              (conv): Sequential(
                (0): Conv2d(160, 1760, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (1): SyncBatchNorm(1760, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)
                (2): ReLU6(inplace=True)
                (3): Conv2d(1760, 1760, kernel_size=(5, 5), stride=(2, 2), padding=(2, 2), groups=1760, bias=False)
                (4): SyncBatchNorm(1760, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)
                (5): Identity()
                (6): ReLU6(inplace=True)
                (7): Conv2d(1760, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (8): SyncBatchNorm(320, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)
              )
            )
            (1): SPPBottleneck(
              (conv1): ConvBNAct(
                (conv): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (bn): SyncBatchNorm(160, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)
                (act): ReLU6(inplace=True) # fixed
              )
              (m): ModuleList(
                (0): MaxPool2d(kernel_size=5, stride=1, padding=2, dilation=1, ceil_mode=False)
                (1): MaxPool2d(kernel_size=9, stride=1, padding=4, dilation=1, ceil_mode=False)
                (2): MaxPool2d(kernel_size=13, stride=1, padding=6, dilation=1, ceil_mode=False)
              )
              (conv2): ConvBNAct(
                (conv): Conv2d(640, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (bn): SyncBatchNorm(320, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)
                (act): ReLU6(inplace=True) # fixed
              )
            )
            (2): MobileV3Block(
              (conv): Sequential(
                (0): Conv2d(320, 1760, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (1): SyncBatchNorm(1760, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)
                (2): ReLU6(inplace=True)
                (3): Conv2d(1760, 1760, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2), groups=1760, bias=False)
                (4): SyncBatchNorm(1760, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)
                (5): Identity()
                (6): ReLU6(inplace=True)
                (7): Conv2d(1760, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)
                (8): SyncBatchNorm(320, eps=0.001, momentum=0.03, affine=True, track_running_stats=True)
              )
            )
          )
        )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: cv2.error: OpenCV(4.9.0) 👎 error: (-5:Bad argument) in function 'rectangle'
1 participant