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

Instantiate AstroPredictor with in-memory model weights #84

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions src/deepdisc/astrodet/astrodet.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
inputs = cv2.imread("input.jpg")
outputs = pred(inputs)
"""
def __init__(self, cfg, lazy=False, cfglazy=None):
def __init__(self, cfg, lazy=False, cfglazy=None, checkpoint=None):

Check warning on line 258 in src/deepdisc/astrodet/astrodet.py

View check run for this annotation

Codecov / codecov/patch

src/deepdisc/astrodet/astrodet.py#L258

Added line #L258 was not covered by tests
self.cfg = copy.deepcopy(cfg) # cfg can be modified by model

if "model" in self.cfg: # This is when were using a LazyConfig-style model in the solo config
Expand All @@ -271,8 +271,14 @@
self.metadata = MetadataCatalog.get(cfg.DATASETS.TEST[0])

checkpointer = DetectionCheckpointer(self.model)
checkpointer.load(cfg.MODEL.WEIGHTS)

# If we provide AstroPredictor with a checkpoint already loaded in memory
# just simply load the weights into the model.
if checkpoint:
checkpointer._load_model(checkpoint)

Check warning on line 278 in src/deepdisc/astrodet/astrodet.py

View check run for this annotation

Codecov / codecov/patch

src/deepdisc/astrodet/astrodet.py#L277-L278

Added lines #L277 - L278 were not covered by tests
else:
checkpointer.load(cfg.train.init_checkpoint)

Check warning on line 280 in src/deepdisc/astrodet/astrodet.py

View check run for this annotation

Codecov / codecov/patch

src/deepdisc/astrodet/astrodet.py#L280

Added line #L280 was not covered by tests

self.aug = T.ResizeShortestEdge(
[cfg.INPUT.MIN_SIZE_TEST, cfg.INPUT.MIN_SIZE_TEST], cfg.INPUT.MAX_SIZE_TEST
)
Expand Down
4 changes: 2 additions & 2 deletions src/deepdisc/inference/predictors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import deepdisc.astrodet.astrodet as toolkit


def return_predictor_transformer(cfg):
def return_predictor_transformer(cfg, checkpoint=None):

Check warning on line 4 in src/deepdisc/inference/predictors.py

View check run for this annotation

Codecov / codecov/patch

src/deepdisc/inference/predictors.py#L4

Added line #L4 was not covered by tests
"""This function returns a trained model and its config file.

Used for models with lazy config files. Also assumes a cascade roi head structure.
Expand All @@ -15,7 +15,7 @@
torch model

"""
predictor = toolkit.AstroPredictor(cfg)
predictor = toolkit.AstroPredictor(cfg, checkpoint=checkpoint)

Check warning on line 18 in src/deepdisc/inference/predictors.py

View check run for this annotation

Codecov / codecov/patch

src/deepdisc/inference/predictors.py#L18

Added line #L18 was not covered by tests
return predictor


Expand Down