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] Fix the error of no num_class #2200

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions paddleseg/cvlibs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,22 @@ def model(self) -> paddle.nn.Layer:
model_cfg = self.dic.get('model').copy()
if not model_cfg:
raise RuntimeError('No model specified in the configuration file.')

if not 'num_classes' in model_cfg:
num_classes = None
try:
if self.train_dataset_config:
if hasattr(self.train_dataset_class, 'NUM_CLASSES'):
num_classes = self.train_dataset_class.NUM_CLASSES
elif 'num_classes' in self.train_dataset_config:
num_classes = self.train_dataset_config['num_classes']
elif hasattr(self.train_dataset, 'num_classes'):
num_classes = self.train_dataset.num_classes
elif self.val_dataset_config:
if hasattr(self.val_dataset_class, 'NUM_CLASSES'):
num_classes = self.val_dataset_class.NUM_CLASSES
elif 'num_classes' in self.val_dataset_config:
num_classes = self.val_dataset_config['num_classes']
elif hasattr(self.val_dataset, 'num_classes'):
num_classes = self.val_dataset.num_classes
except FileNotFoundError:
Expand Down