Skip to content

Refactor pytorch logic - #130

Merged
Sarah5567 merged 6 commits into
mainfrom
refactor-pytorch-logic
Nov 11, 2025
Merged

Sarah5567 merged 6 commits into
mainfrom
refactor-pytorch-logic

Conversation

@Sarah5567

Copy link
Copy Markdown
Collaborator

This PR refactors the PyTorch-related inference modules to improve structure, readability, and maintainability.

Changes

  • Moved all PyTorch inference classes (ResNetInference, MobileNetInference) into src/inference/pytorch/.
  • Kept only shared abstract logic in src/inference/base/classifier_inference_base.py.
  • Introduced InferenceFactory to instantiate model classes dynamically.
  • Moved utility functions into src/inference/utils/ with logical grouping.
  • Verified identical results between pre-refactor and refactored scripts.

closes #119

@Sarah5567 Sarah5567 linked an issue Nov 11, 2025 that may be closed by this pull request
device=device,
weights_path=model_path,
class_mapping=class_mapping,
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model_class = mapping[model_type]
        return model_class(
            device=device,
            weights_path=model_path,
            class_mapping=class_mapping,
        )

Dead code at end of create() method - remove the unreachable model_class = mapping[model_type] lines.

Comment thread scripts/export_to_onnx.py Outdated
@@ -1,37 +1,28 @@
#!/usr/bin/env python3

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not needed

Comment thread scripts/onnx_validation.py Outdated
@@ -1,15 +1,18 @@
#!/usr/bin/env python3

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not needed

Comment thread src/evaluation/evaluator.py Outdated
import torch
from PIL import Image

from src.inference.base.classifier_inference_base import ClassifierInferenceBase as InferenceModel

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please import it as is, and use directly ClassifierInferenceBase?



# Main image processing logic
def process_images_with_oop(model_type: str, model_path: str, image_dir: str, device: str):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rename this function

@Sarah5567
Sarah5567 merged commit 6c01e55 into main Nov 11, 2025
1 check failed
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.

Refactor pytorch-related inference logic

3 participants