Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
constantinpape committed Apr 12, 2024
2 parents 8cafd51 + d177934 commit 3c2399d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
22 changes: 8 additions & 14 deletions doc/installation.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
# Installation

We provide three different ways of installing `micro_sam`:
There are three ways to install `micro_sam`:
- [From mamba](#from-mamba) is the recommended way if you want to use all functionality.
- [From source](#from-source) for setting up a development environment to use the latest version and be able to change and contribute to our software.
- [From installer](#from-installer) to install without having to use conda. This mode of installation is still experimental! It only provides the annotation tools and does not enable model finetuning.

Our software requires the following dependencies:
- [PyTorch](https://pytorch.org/get-started/locally/)
- [SegmentAnything](https://github.com/facebookresearch/segment-anything#installation)
- [elf](https://github.com/constantinpape/elf)
- [torch_em](https://github.com/constantinpape/torch-em)
- [napari](https://napari.org/stable/) (for the interactive annotation tools)

- [From installer](#from-installer) to install without having to use conda (supported platforms: Windows and Linux, only for CPU users).

## From mamba

[mamba](https://mamba.readthedocs.io/en/latest/) is a drop-in replacement for conda, but is much faster than it.
[mamba](https://mamba.readthedocs.io/en/latest/) is a drop-in replacement for conda, but much faster.
While the steps below may also work with `conda`, we highly recommend using `mamba`.
You can follow the instrutions [here](https://mamba.readthedocs.io/en/latest/installation/mamba-installation.html) to install `mamba`.
You can follow the instructions [here](https://mamba.readthedocs.io/en/latest/installation/mamba-installation.html) to install `mamba`.

**IMPORTANT**: Make sure to avoid installing anything in the base environment.

`micro_sam` can then be installed in an existing environment via
`micro_sam` can be installed in an existing environment via:
```
$ mamba install -c conda-forge micro_sam
```
or you can create a new environment (here called `micro-sam`) via
or you should create a new environment (here called `micro-sam`) via:
```
$ mamba create -c conda-forge -n micro-sam micro_sam
```
Expand Down
6 changes: 4 additions & 2 deletions micro_sam/training/joint_sam_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ def __init__(
self.instance_loss = instance_loss
self.instance_metric = instance_metric

def save_checkpoint(self, name, best_metric, **extra_save_dict):
def save_checkpoint(self, name, current_metric, best_metric, **extra_save_dict):
current_unetr_state = self.unetr.state_dict()
decoder_state = []
for k, v in current_unetr_state.items():
if not k.startswith("encoder"):
decoder_state.append((k, v))
decoder_state = OrderedDict(decoder_state)

super().save_checkpoint(name, best_metric, decoder_state=decoder_state, **extra_save_dict)
super().save_checkpoint(
name, current_metric=current_metric, best_metric=best_metric, decoder_state=decoder_state, **extra_save_dict
)

def load_checkpoint(self, checkpoint="best"):
save_dict = super().load_checkpoint(checkpoint)
Expand Down
2 changes: 1 addition & 1 deletion micro_sam/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ def segmentation_to_one_hot(
n_ids = int(segmentation.max())

else:
assert segmentation_ids[0] != 0
assert segmentation_ids[0] != 0, "No objects were found."

# the segmentation ids have to be sorted
segmentation_ids = np.sort(segmentation_ids)
Expand Down

0 comments on commit 3c2399d

Please sign in to comment.