-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cosem Starter using Cellmap_models ```python from dacapo.experiments.starts import CosemStartConfig starter_config = CosemStartConfig(name='setup04/1820500') ```
- Loading branch information
Showing
7 changed files
with
81 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
from .start import Start # noqa | ||
from .start_config import StartConfig # noqa | ||
from .cosem_start import CosemStart # noqa | ||
from .cosem_start_config import CosemStartConfig # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from abc import ABC | ||
import logging | ||
from cellmap_models import cosem | ||
from pathlib import Path | ||
from .start import Start | ||
|
||
logger = logging.getLogger(__file__) | ||
|
||
|
||
def format_name(name): | ||
if "/" in name: | ||
run, criterion = name.split("/") | ||
return run, criterion | ||
else: | ||
raise ValueError( | ||
f"Invalid starter name format {name}. Must be in the format run/criterion" | ||
) | ||
|
||
|
||
class CosemStart(Start): | ||
def __init__(self, start_config): | ||
run, criterion = format_name(start_config.name) | ||
self.name = start_config.name | ||
super().__init__(run, criterion) | ||
|
||
def initialize_weights(self, model): | ||
from dacapo.store.create_store import create_weights_store | ||
|
||
weights_store = create_weights_store() | ||
weights_dir = Path(weights_store.basedir, self.run, "checkpoints", "iterations") | ||
if not (weights_dir / self.criterion).exists(): | ||
if not weights_dir.exists(): | ||
weights_dir.mkdir(parents=True, exist_ok=True) | ||
path = weights_dir / self.criterion | ||
cosem.download_checkpoint(self.name, path) | ||
weights = weights_store._retrieve_weights(self.run, self.criterion) | ||
super._set_weights(model, weights) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import attr | ||
from .cosem_start import CosemStart | ||
|
||
|
||
@attr.s | ||
class CosemStartConfig: | ||
"""Starter for COSEM pretained models. This is a subclass of `StartConfig` and | ||
should be used to initialize the model with pretrained weights from a previous | ||
run. | ||
""" | ||
|
||
start_type = CosemStart | ||
|
||
name: str = attr.ib(metadata={"help_text": "The COSEM checkpoint name to use."}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters