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 classnames #210

Merged
merged 3 commits into from
Nov 14, 2023
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
9 changes: 6 additions & 3 deletions src/data_gradients/dataset_adapters/config/data_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import torch
from abc import ABC
from dataclasses import dataclass
from typing import Dict, Optional, Callable, Union, List
from typing import Dict, Optional, Callable, Union, List, Mapping

import data_gradients
from data_gradients.dataset_adapters.config.questions import FixedOptionsQuestion, OpenEndedQuestion, text_to_yellow
Expand Down Expand Up @@ -152,7 +152,10 @@ def _fill_missing_params(self, json_dict: JSONDict):
if self.n_classes is None:
self.n_classes = json_dict.get("n_classes")
if self.class_names is None:
self.class_names = json_dict.get("class_names")
class_names = json_dict.get("class_names")
if isinstance(class_names, Mapping):
class_names = {int(k): v for k, v in class_names.items()}
self.class_names = class_names
if self.class_names_to_use is None:
self.class_names_to_use = json_dict.get("class_names_to_use")
if self.image_channels is None:
Expand Down Expand Up @@ -342,7 +345,7 @@ def _represents_int(s: str) -> bool:
validation=lambda answer: _represents_int(answer) and int(answer) > 0,
)
n_classes = int(question.ask())
return {f"class_{i}": i for i in range(n_classes)}
return {i: f"class_{i}" for i in range(n_classes)}
elif class_names:
if isinstance(class_names, list):
return dict(zip(range(len(class_names)), class_names))
Expand Down