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

nanodet keras model fixed to default 80 coco classes #997

Closed
alexander-sony opened this issue Mar 15, 2024 · 1 comment
Closed

nanodet keras model fixed to default 80 coco classes #997

alexander-sony opened this issue Mar 15, 2024 · 1 comment
Assignees

Comments

@alexander-sony
Copy link
Collaborator

Issue Type

Bug

Source

source

MCT Version

1.10.0

OS Platform and Distribution

Ubuntu 20.04

Python version

3.10.12

Describe the issue

re: tutorials/mct_model_garden/models_keras/nanodet/nanodet_keras_model.py

nanodet_keras_model.py can only handle 80 classes

Can be made more general by replacing the value of 80 with a class parameter
- see def nanodet_box_decoding()

Moreover, in nanodet_plus_head(n, feat_channels=128)
h[idx] = Conv2D(112, 1, name='head.gfl_cls.' + str(idx))(h[idx])
should probably be replaced with
h[idx] = Conv2D(32+num_of_classes, 1, name='head.gfl_cls.' + str(idx))(h[idx])
where num_of_classes corresponds to a new input parameter (default is 80 as in coco)

Expected behaviour

expected to be able to load pth file with a different number of classes than in coco (80)

Code to reproduce the issue

# see https://github.com/sony/model_optimization/blob/main/tutorials/notebooks/keras/ptq/example_keras_nanodet_plus.ipynb
PRETRAINED_WEIGHTS_FILE = <pth file with num of classes != 80>
# Parameters for nanodet-plus-m-1.5x_416
INPUT_RESOLUTION = 416
INPUT_SHAPE = (INPUT_RESOLUTION, INPUT_RESOLUTION, 3)
SCALE_FACTOR = 1.5
BOTTLENECK_RATIO = 0.5
FEATURE_CHANNELS = 128

pretrained_weights = torch.load(PRETRAINED_WEIGHTS_FILE, map_location=torch.device('cpu'))['state_dict']
model = nanodet_plus_m(INPUT_SHAPE, SCALE_FACTOR, BOTTLENECK_RATIO, FEATURE_CHANNELS)
load_state_dict(model, state_dict_torch=pretrained_weights)  # ValueError
...

Log output

(tested with 5 classes instead of 80)
...torch2keras_weights_translation.py", line 15

ValueError: Cannot assign value to variable ' head.gfl_cls.0/kernel:0': Shape mismatch.The variable shape (1, 1, 128, 112), and the assigned value shape (1, 1, 128, 37) are incompatible
@Idan-BenAmi
Copy link
Collaborator

Nanodet keras model in MCT Mode Garden supports configurable number of classes #1000

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

No branches or pull requests

2 participants