torch-em 0.9.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- torch_em-0.9.0/LICENSE +21 -0
- torch_em-0.9.0/PKG-INFO +27 -0
- torch_em-0.9.0/README.md +80 -0
- torch_em-0.9.0/pyproject.toml +3 -0
- torch_em-0.9.0/setup.cfg +4 -0
- torch_em-0.9.0/setup.py +45 -0
- torch_em-0.9.0/test/data/__init__.py +0 -0
- torch_em-0.9.0/test/data/test_dataset_wrapper.py +36 -0
- torch_em-0.9.0/test/data/test_image_collection_dataset.py +108 -0
- torch_em-0.9.0/test/data/test_raw_dataset.py +173 -0
- torch_em-0.9.0/test/data/test_sampler.py +35 -0
- torch_em-0.9.0/test/data/test_segmentation_dataset.py +210 -0
- torch_em-0.9.0/test/data/test_tensor_dataset.py +68 -0
- torch_em-0.9.0/test/loss/__init__.py +0 -0
- torch_em-0.9.0/test/loss/test_cldice.py +68 -0
- torch_em-0.9.0/test/loss/test_contrastive.py +126 -0
- torch_em-0.9.0/test/loss/test_contrastive_impl.py +134 -0
- torch_em-0.9.0/test/loss/test_dice.py +69 -0
- torch_em-0.9.0/test/loss/test_loss_wrapper.py +154 -0
- torch_em-0.9.0/test/loss/test_spoco.py +67 -0
- torch_em-0.9.0/test/metric/__init__.py +0 -0
- torch_em-0.9.0/test/metric/test_cldice.py +47 -0
- torch_em-0.9.0/test/metric/test_metric.py +149 -0
- torch_em-0.9.0/test/model/__init__.py +0 -0
- torch_em-0.9.0/test/model/test_punet.py +56 -0
- torch_em-0.9.0/test/model/test_resnet3d.py +27 -0
- torch_em-0.9.0/test/model/test_unet.py +82 -0
- torch_em-0.9.0/test/model/test_unetr.py +94 -0
- torch_em-0.9.0/test/self_training/__init__.py +0 -0
- torch_em-0.9.0/test/self_training/test_fix_match.py +127 -0
- torch_em-0.9.0/test/self_training/test_mean_teacher.py +128 -0
- torch_em-0.9.0/test/test_classification.py +85 -0
- torch_em-0.9.0/test/test_cli.py +94 -0
- torch_em-0.9.0/test/test_segmentation.py +231 -0
- torch_em-0.9.0/test/trainer/__init__.py +0 -0
- torch_em-0.9.0/test/trainer/test_default_trainer.py +162 -0
- torch_em-0.9.0/test/trainer/test_spoco_trainer.py +123 -0
- torch_em-0.9.0/test/transform/__init__.py +0 -0
- torch_em-0.9.0/test/transform/test_augmentations.py +29 -0
- torch_em-0.9.0/test/transform/test_generic.py +54 -0
- torch_em-0.9.0/test/transform/test_invertible_augmentations.py +138 -0
- torch_em-0.9.0/test/transform/test_label_transforms.py +229 -0
- torch_em-0.9.0/test/transform/test_raw.py +103 -0
- torch_em-0.9.0/test/util/__init__.py +0 -0
- torch_em-0.9.0/test/util/test_imageio.py +29 -0
- torch_em-0.9.0/test/util/test_modelzoo.py +119 -0
- torch_em-0.9.0/test/util/test_prediction.py +90 -0
- torch_em-0.9.0/test/util/test_segmentation.py +82 -0
- torch_em-0.9.0/test/util/test_util.py +64 -0
- torch_em-0.9.0/torch_em/__init__.py +11 -0
- torch_em-0.9.0/torch_em/__version__.py +1 -0
- torch_em-0.9.0/torch_em/classification/__init__.py +6 -0
- torch_em-0.9.0/torch_em/classification/classification.py +126 -0
- torch_em-0.9.0/torch_em/classification/classification_dataset.py +65 -0
- torch_em-0.9.0/torch_em/classification/classification_logger.py +137 -0
- torch_em-0.9.0/torch_em/classification/classification_trainer.py +42 -0
- torch_em-0.9.0/torch_em/cli.py +413 -0
- torch_em-0.9.0/torch_em/data/__init__.py +18 -0
- torch_em-0.9.0/torch_em/data/concat_dataset.py +39 -0
- torch_em-0.9.0/torch_em/data/dataset_wrapper.py +23 -0
- torch_em-0.9.0/torch_em/data/datasets/__init__.py +13 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/__init__.py +48 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/aimseg.py +159 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/asem.py +256 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/astih.py +340 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/axondeepseg.py +277 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/axonem.py +150 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/betaseg.py +166 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/cellmap.py +550 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/cem.py +382 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/cremi.py +251 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/deepict.py +178 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/densecell.py +197 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/emneuron.py +153 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/emps.py +185 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/fafb.py +241 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/fafb_nuclei.py +116 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/fib25.py +215 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/hemibrain.py +243 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/human_cortex_h01.py +242 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/human_organoids.py +179 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/hydra_vulgaris.py +299 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/isbi2012.py +121 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/kasthuri.py +173 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/lucchi.py +174 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/malecns.py +214 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/manc.py +197 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/microns.py +527 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/microns_nuclei.py +119 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/mitoem.py +274 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/mitoemv2.py +309 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/mousecc.py +180 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/nisb.py +283 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/nuc_mm.py +159 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/platynereis.py +448 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/probtem.py +179 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/snemi.py +135 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/sponge_em.py +137 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/synapseweb_hippocampus.py +200 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/uro_cell.py +226 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/vnc.py +163 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/waenet.py +293 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/wildenberg.py +384 -0
- torch_em-0.9.0/torch_em/data/datasets/electron_microscopy/zebrafinch.py +312 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/__init__.py +23 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/bcss.py +243 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/conic.py +234 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/consep.py +209 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/cpm.py +221 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/cryonuseg.py +186 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/cytodark0.py +211 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/glas.py +172 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/glysac.py +182 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/hest.py +735 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/janowczyk.py +231 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/lizard.py +194 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/lynsec.py +222 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/monusac.py +294 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/monuseg.py +248 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/nuclick.py +149 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/nuinsseg.py +128 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/orion_crc.py +526 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/pannuke.py +277 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/panoptils.py +195 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/pcns.py +325 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/puma.py +345 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/segpath.py +336 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/srsanet.py +167 -0
- torch_em-0.9.0/torch_em/data/datasets/histopathology/tnbc.py +200 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/__init__.py +83 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/aisegcell.py +210 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/arvidsson.py +179 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/bac_mother.py +136 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/balf.py +268 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/bbbc030.py +214 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/bbbc034.py +155 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/bccd.py +206 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/bitdepth_nucseg.py +156 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/blastospim.py +139 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/bmgd.py +236 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/brain_organoids.py +131 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/brifiseg.py +166 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/cartocell.py +145 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/celegans_atlas.py +134 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/cellbindb.py +166 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/cellpose.py +176 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/cellseg_3d.py +126 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/cisd.py +278 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/covid_if.py +166 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/cshaper.py +231 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/ctc.py +226 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/cvz_fluo.py +172 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/deepbacs.py +213 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/deepseas.py +142 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/dic_hepg2.py +190 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/dsb.py +248 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/dynamicnuclearnet.py +170 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/e11bio.py +259 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/embedseg_data.py +147 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/enseg.py +234 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/evican.py +335 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/glioma_c6.py +234 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/gonuclear.py +245 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/hpa.py +453 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/idr0095.py +274 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/ifnuclei.py +107 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/liconn.py +271 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/livecell.py +305 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/lpc_nucseg.py +201 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/lsm_mouse_embryo.py +210 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/medussa.py +228 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/microbeseg.py +174 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/mndino.py +230 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/morphonet.py +247 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/morphoseg.py +216 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/mouse_embryo.py +153 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/mucic.py +484 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/neurips_cell_seg.py +361 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/neurosphere.py +176 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/nis3d.py +156 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/nisnet3d.py +191 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/nuc_morph.py +238 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/omnipose.py +171 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/oocyteseg.py +234 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/orgaextractor.py +160 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/organoid.py +270 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/organoidnet.py +148 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/orgasegment.py +144 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/orgline.py +282 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/parhyale_regen.py +140 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/phmamm.py +154 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/plantseg.py +244 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/pnas_arabidopsis.py +140 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/scaffold_a549.py +171 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/segpc.py +175 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/slimia.py +235 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/spheroids_hepg2.py +139 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/synthmt.py +191 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/tissuenet.py +192 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/toiam.py +111 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/u20s.py +159 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/usiigaci.py +124 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/vgg_hela.py +160 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/vibrio_cholerae.py +137 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/vicar.py +152 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/wing_disc.py +198 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/xpress.py +149 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/yeastcellseg.py +187 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/yeastms.py +196 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/yeastsam.py +131 -0
- torch_em-0.9.0/torch_em/data/datasets/light_microscopy/yeaz.py +181 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/__init__.py +60 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/abus.py +165 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/acdc.py +162 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/acouslic_ai.py +125 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/amd_sd.py +190 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/amos.py +179 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/autopet.py +152 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/btcv.py +229 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/busi.py +142 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/camus.py +141 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/cbis_ddsm.py +195 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/chaos.py +236 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/cholecseg8k.py +203 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/covid19_seg.py +171 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/covid_qu_ex.py +190 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/ct_cadaiver.py +131 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/curvas.py +194 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/dca1.py +149 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/drive.py +176 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/dsad.py +154 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/duke_liver.py +208 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/feta24.py +144 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/fundus_avseg.py +180 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/han_seg.py +166 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/hil_toothseg.py +174 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/idrid.py +164 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/ircadb.py +201 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/isic.py +190 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/isles.py +141 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/jnuifm.py +122 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/jsrt.py +179 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/kits.py +303 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/kvasir.py +147 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/leg_3d_us.py +190 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/lgg_mri.py +183 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/m2caiseg.py +213 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/mbh_seg.py +125 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/mice_tumseg.py +157 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/micro_usp.py +141 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/montgomery.py +155 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/motum.py +161 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/msd.py +180 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/oasis.py +162 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/oimhs.py +205 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/osic_pulmofib.py +234 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/palm.py +174 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/panorama.py +193 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/papila.py +205 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/pengwin.py +168 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/piccolo.py +149 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/plethora.py +238 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/psfhs.py +148 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/ravir.py +133 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/sa_med2d.py +431 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/sega.py +201 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/segthy.py +204 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/siim_acr.py +179 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/spider.py +142 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/toothfairy.py +223 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/uwaterloo_skin.py +161 -0
- torch_em-0.9.0/torch_em/data/datasets/medical/verse.py +142 -0
- torch_em-0.9.0/torch_em/data/datasets/util.py +593 -0
- torch_em-0.9.0/torch_em/data/image_collection_dataset.py +264 -0
- torch_em-0.9.0/torch_em/data/pseudo_label_dataset.py +86 -0
- torch_em-0.9.0/torch_em/data/raw_dataset.py +383 -0
- torch_em-0.9.0/torch_em/data/raw_image_collection_dataset.py +187 -0
- torch_em-0.9.0/torch_em/data/sampler.py +233 -0
- torch_em-0.9.0/torch_em/data/segmentation_dataset.py +287 -0
- torch_em-0.9.0/torch_em/data/tensor_dataset.py +90 -0
- torch_em-0.9.0/torch_em/loss/__init__.py +15 -0
- torch_em-0.9.0/torch_em/loss/affinity_side_loss.py +172 -0
- torch_em-0.9.0/torch_em/loss/cldice.py +216 -0
- torch_em-0.9.0/torch_em/loss/combined_loss.py +38 -0
- torch_em-0.9.0/torch_em/loss/contrastive.py +169 -0
- torch_em-0.9.0/torch_em/loss/contrastive_impl.py +272 -0
- torch_em-0.9.0/torch_em/loss/dice.py +256 -0
- torch_em-0.9.0/torch_em/loss/distance_based.py +69 -0
- torch_em-0.9.0/torch_em/loss/spoco_loss.py +643 -0
- torch_em-0.9.0/torch_em/loss/wrapper.py +183 -0
- torch_em-0.9.0/torch_em/metric/__init__.py +8 -0
- torch_em-0.9.0/torch_em/metric/cldice.py +63 -0
- torch_em-0.9.0/torch_em/metric/instance_segmentation_metric.py +483 -0
- torch_em-0.9.0/torch_em/model/__init__.py +8 -0
- torch_em-0.9.0/torch_em/model/probabilistic_unet.py +475 -0
- torch_em-0.9.0/torch_em/model/resnet3d.py +518 -0
- torch_em-0.9.0/torch_em/model/unet.py +728 -0
- torch_em-0.9.0/torch_em/model/unetr.py +1018 -0
- torch_em-0.9.0/torch_em/model/vim.py +267 -0
- torch_em-0.9.0/torch_em/model/vit.py +1017 -0
- torch_em-0.9.0/torch_em/multi_gpu_training.py +190 -0
- torch_em-0.9.0/torch_em/segmentation.py +574 -0
- torch_em-0.9.0/torch_em/self_training/__init__.py +13 -0
- torch_em-0.9.0/torch_em/self_training/augmentations.py +4 -0
- torch_em-0.9.0/torch_em/self_training/fix_match.py +689 -0
- torch_em-0.9.0/torch_em/self_training/logger.py +404 -0
- torch_em-0.9.0/torch_em/self_training/loss.py +406 -0
- torch_em-0.9.0/torch_em/self_training/mean_teacher.py +723 -0
- torch_em-0.9.0/torch_em/self_training/probabilistic_unet_trainer.py +117 -0
- torch_em-0.9.0/torch_em/self_training/pseudo_labeling.py +397 -0
- torch_em-0.9.0/torch_em/self_training/uni_match_v2.py +435 -0
- torch_em-0.9.0/torch_em/shallow2deep/__init__.py +8 -0
- torch_em-0.9.0/torch_em/shallow2deep/prepare_shallow2deep.py +880 -0
- torch_em-0.9.0/torch_em/shallow2deep/pseudolabel_training.py +162 -0
- torch_em-0.9.0/torch_em/shallow2deep/shallow2deep_dataset.py +403 -0
- torch_em-0.9.0/torch_em/shallow2deep/shallow2deep_eval.py +231 -0
- torch_em-0.9.0/torch_em/shallow2deep/shallow2deep_model.py +205 -0
- torch_em-0.9.0/torch_em/shallow2deep/transform.py +86 -0
- torch_em-0.9.0/torch_em/trainer/__init__.py +3 -0
- torch_em-0.9.0/torch_em/trainer/default_trainer.py +852 -0
- torch_em-0.9.0/torch_em/trainer/flashoptim_trainer.py +111 -0
- torch_em-0.9.0/torch_em/trainer/logger_base.py +18 -0
- torch_em-0.9.0/torch_em/trainer/spoco_trainer.py +152 -0
- torch_em-0.9.0/torch_em/trainer/tensorboard_logger.py +162 -0
- torch_em-0.9.0/torch_em/trainer/wandb_logger.py +118 -0
- torch_em-0.9.0/torch_em/transform/__init__.py +8 -0
- torch_em-0.9.0/torch_em/transform/augmentation.py +302 -0
- torch_em-0.9.0/torch_em/transform/defect.py +245 -0
- torch_em-0.9.0/torch_em/transform/generic.py +235 -0
- torch_em-0.9.0/torch_em/transform/invertible_augmentations.py +199 -0
- torch_em-0.9.0/torch_em/transform/label.py +633 -0
- torch_em-0.9.0/torch_em/transform/nnunet_raw.py +96 -0
- torch_em-0.9.0/torch_em/transform/raw.py +389 -0
- torch_em-0.9.0/torch_em/util/__init__.py +21 -0
- torch_em-0.9.0/torch_em/util/debug.py +178 -0
- torch_em-0.9.0/torch_em/util/grid_search.py +232 -0
- torch_em-0.9.0/torch_em/util/image.py +115 -0
- torch_em-0.9.0/torch_em/util/modelzoo.py +893 -0
- torch_em-0.9.0/torch_em/util/prediction.py +320 -0
- torch_em-0.9.0/torch_em/util/reporting.py +77 -0
- torch_em-0.9.0/torch_em/util/segmentation.py +233 -0
- torch_em-0.9.0/torch_em/util/submit_slurm.py +103 -0
- torch_em-0.9.0/torch_em/util/test.py +59 -0
- torch_em-0.9.0/torch_em/util/training.py +19 -0
- torch_em-0.9.0/torch_em/util/util.py +486 -0
- torch_em-0.9.0/torch_em/util/validation.py +265 -0
- torch_em-0.9.0/torch_em.egg-info/PKG-INFO +27 -0
- torch_em-0.9.0/torch_em.egg-info/SOURCES.txt +350 -0
- torch_em-0.9.0/torch_em.egg-info/dependency_links.txt +1 -0
- torch_em-0.9.0/torch_em.egg-info/entry_points.txt +7 -0
- torch_em-0.9.0/torch_em.egg-info/requires.txt +15 -0
- torch_em-0.9.0/torch_em.egg-info/top_level.txt +2 -0
torch_em-0.9.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Constantin Pape
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
torch_em-0.9.0/PKG-INFO
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: torch_em
|
|
3
|
+
Version: 0.9.0
|
|
4
|
+
Home-page: https://github.com/constantinpape/torch-em
|
|
5
|
+
Author: Constantin Pape
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: bioimage-cpp
|
|
9
|
+
Requires-Dist: bioimageio.core
|
|
10
|
+
Requires-Dist: h5py
|
|
11
|
+
Requires-Dist: imageio
|
|
12
|
+
Requires-Dist: kornia
|
|
13
|
+
Requires-Dist: mrcfile
|
|
14
|
+
Requires-Dist: natsort
|
|
15
|
+
Requires-Dist: python-elf>=0.9.1
|
|
16
|
+
Requires-Dist: requests
|
|
17
|
+
Requires-Dist: scikit-image
|
|
18
|
+
Requires-Dist: tensorboard
|
|
19
|
+
Requires-Dist: tifffile
|
|
20
|
+
Requires-Dist: torch
|
|
21
|
+
Requires-Dist: torchvision
|
|
22
|
+
Requires-Dist: tqdm
|
|
23
|
+
Dynamic: author
|
|
24
|
+
Dynamic: home-page
|
|
25
|
+
Dynamic: license
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
Dynamic: requires-dist
|
torch_em-0.9.0/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
[](https://constantinpape.github.io/torch-em/torch_em.html)
|
|
2
|
+
[](https://github.com/constantinpape/torch-em/actions)
|
|
3
|
+
[](https://doi.org/10.5281/zenodo.5108853)
|
|
4
|
+
[](https://anaconda.org/conda-forge/torch_em)
|
|
5
|
+
|
|
6
|
+
# torch-em
|
|
7
|
+
|
|
8
|
+
Deep-learning based semantic and instance segmentation for 3D Electron Microscopy and other bioimage analysis problems based on PyTorch. Any feedback is highly appreciated, just open an issue!
|
|
9
|
+
|
|
10
|
+
**Important:** We recently migrated `torch_em` to [bioimage-cpp](https://github.com/computational-cell-analytics/bioimage-cpp). This enables installing `torch_em` via pip (in addition to conda) but changes dependencies and may still lead to some bugs. Please report any problems you encounter in an issue; you can pin `torch_em < 0.9` to install a version based on previous dependencies.
|
|
11
|
+
|
|
12
|
+
Highlights:
|
|
13
|
+
- Functional API with sensible defaults to train a state-of-the-art segmentation model with a few lines of code.
|
|
14
|
+
- Differentiable augmentations on GPU and CPU thanks to [kornia](https://github.com/kornia/kornia).
|
|
15
|
+
- Off-the-shelf logging with [tensorboard](https://www.tensorflow.org/tensorboard) or [wandb](https://wandb.ai/site).
|
|
16
|
+
- Export trained models to [bioimage.io](https://bioimage.io/#/) model format with one function call to deploy them in [ilastik](https://www.ilastik.org/documentation/nn/nn) or [deepimageJ](https://deepimagej.github.io/deepimagej/).
|
|
17
|
+
|
|
18
|
+
Design:
|
|
19
|
+
- All parameters are specified in code, no configuration files.
|
|
20
|
+
- No callback logic; to extend the core functionality inherit from `torch_em.trainer.DefaultTrainer` instead.
|
|
21
|
+
- All data-loading is lazy to support training on large datasets.
|
|
22
|
+
|
|
23
|
+
`torch_em` can be installed via conda: `conda install -c conda-forge torch_em`.
|
|
24
|
+
Find an example script for how to train a 2D U-Net with it below and check out the [documentation](https://constantinpape.github.io/torch-em/torch_em.html) for more details.
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
# Train a 2d U-Net for foreground and boundary segmentation of nuclei, using data from
|
|
28
|
+
# https://github.com/mpicbg-csbd/stardist/releases/download/0.1.0/dsb2018.zip
|
|
29
|
+
|
|
30
|
+
import torch_em
|
|
31
|
+
from torch_em.model import UNet2d
|
|
32
|
+
from torch_em.data.datasets import get_dsb_loader
|
|
33
|
+
|
|
34
|
+
model = UNet2d(in_channels=1, out_channels=2)
|
|
35
|
+
|
|
36
|
+
# Transform to convert from instance segmentation labels to foreground and boundary probabilties.
|
|
37
|
+
label_transform = torch_em.transform.BoundaryTransform(add_binary_target=True, ndim=2)
|
|
38
|
+
|
|
39
|
+
# Create the training and validation data loader.
|
|
40
|
+
data_path = "./dsb" # The training data will be downloaded and saved here.
|
|
41
|
+
train_loader = get_dsb_loader(
|
|
42
|
+
data_path,
|
|
43
|
+
patch_shape=(1, 256, 256),
|
|
44
|
+
batch_size=8,
|
|
45
|
+
split="train",
|
|
46
|
+
download=True,
|
|
47
|
+
label_transform=label_transform,
|
|
48
|
+
)
|
|
49
|
+
val_loader = get_dsb_loader(
|
|
50
|
+
data_path,
|
|
51
|
+
patch_shape=(1, 256, 256),
|
|
52
|
+
batch_size=8,
|
|
53
|
+
split="test",
|
|
54
|
+
label_transform=label_transform,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# The trainer handles the details of the training process.
|
|
58
|
+
# It will save checkpoints in "checkpoints/dsb-boundary-model"
|
|
59
|
+
# and the tensorboard logs in "logs/dsb-boundary-model".
|
|
60
|
+
trainer = torch_em.default_segmentation_trainer(
|
|
61
|
+
name="dsb-boundary-model",
|
|
62
|
+
model=model,
|
|
63
|
+
train_loader=train_loader,
|
|
64
|
+
val_loader=val_loader,
|
|
65
|
+
learning_rate=1e-4,
|
|
66
|
+
)
|
|
67
|
+
trainer.fit(iterations=5000) # Fit for 5000 iterations.
|
|
68
|
+
|
|
69
|
+
# Export the trained model to the bioimage.io model format.
|
|
70
|
+
from glob import glob
|
|
71
|
+
import imageio
|
|
72
|
+
from torch_em.util import export_bioimageio_model
|
|
73
|
+
|
|
74
|
+
# Load one of the images to use as reference image.
|
|
75
|
+
# Crop it to a shape that is guaranteed to fit the network.
|
|
76
|
+
test_im = imageio.imread(glob(f"{data_path}/test/images/*.tif")[0])[:256, :256]
|
|
77
|
+
|
|
78
|
+
# Export the model.
|
|
79
|
+
export_bioimageio_model("./checkpoints/dsb-boundary-model", "./bioimageio-model", test_im)
|
|
80
|
+
```
|
torch_em-0.9.0/setup.cfg
ADDED
torch_em-0.9.0/setup.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import runpy
|
|
2
|
+
from setuptools import setup, find_packages
|
|
3
|
+
|
|
4
|
+
__version__ = runpy.run_path("torch_em/__version__.py")["__version__"]
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
requires = [
|
|
8
|
+
"bioimage-cpp",
|
|
9
|
+
"bioimageio.core",
|
|
10
|
+
"h5py",
|
|
11
|
+
"imageio",
|
|
12
|
+
"kornia",
|
|
13
|
+
"mrcfile",
|
|
14
|
+
"natsort",
|
|
15
|
+
"python-elf >=0.9.1",
|
|
16
|
+
"requests",
|
|
17
|
+
"scikit-image",
|
|
18
|
+
"tensorboard",
|
|
19
|
+
"tifffile",
|
|
20
|
+
"torch",
|
|
21
|
+
"torchvision",
|
|
22
|
+
"tqdm",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
setup(
|
|
27
|
+
name="torch_em",
|
|
28
|
+
packages=find_packages(exclude=["test"]),
|
|
29
|
+
version=__version__,
|
|
30
|
+
author="Constantin Pape",
|
|
31
|
+
install_requires=requires,
|
|
32
|
+
url="https://github.com/constantinpape/torch-em",
|
|
33
|
+
license="MIT",
|
|
34
|
+
entry_points={
|
|
35
|
+
"console_scripts": [
|
|
36
|
+
"torch_em.train_2d_unet = torch_em.cli:train_2d_unet",
|
|
37
|
+
"torch_em.train_3d_unet = torch_em.cli:train_3d_unet",
|
|
38
|
+
"torch_em.predict = torch_em.cli:predict",
|
|
39
|
+
"torch_em.predict_with_tiling = torch_em.cli:predict_with_tiling",
|
|
40
|
+
"torch_em.export_bioimageio_model = torch_em.util.modelzoo:main",
|
|
41
|
+
"torch_em.validate_checkpoint = torch_em.util.validation:main",
|
|
42
|
+
# "torch_em.submit_slurm = torch_em.util.submit_slurm:main",
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import unittest
|
|
3
|
+
|
|
4
|
+
from torch_em.data import SegmentationDataset
|
|
5
|
+
from torch_em.util.test import create_segmentation_test_data
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TestDatasetWrapper(unittest.TestCase):
|
|
9
|
+
path = "./data.h5"
|
|
10
|
+
raw_key = "raw"
|
|
11
|
+
label_key = "labels"
|
|
12
|
+
shape = (32,) * 3
|
|
13
|
+
|
|
14
|
+
def setUp(self):
|
|
15
|
+
create_segmentation_test_data(self.path, self.raw_key, self.label_key, shape=self.shape, chunks=(32,) * 3)
|
|
16
|
+
|
|
17
|
+
def tearDown(self):
|
|
18
|
+
os.remove(self.path)
|
|
19
|
+
|
|
20
|
+
def test_wrap_dataset(self):
|
|
21
|
+
from torch_em.data import DatasetWrapper
|
|
22
|
+
|
|
23
|
+
patch_shape = (32, 32, 32)
|
|
24
|
+
ds = SegmentationDataset(self.path, self.raw_key, self.path, self.label_key, patch_shape=patch_shape)
|
|
25
|
+
wrapped_ds = DatasetWrapper(ds, lambda xy: (xy[0][:, :10, :10, :10], xy[1][:, :20, :20, :20]))
|
|
26
|
+
|
|
27
|
+
expected_shape_x = (1, 10, 10, 10)
|
|
28
|
+
expected_shape_y = (1, 20, 20, 20)
|
|
29
|
+
for i in range(3):
|
|
30
|
+
x, y = wrapped_ds[i]
|
|
31
|
+
self.assertEqual(x.shape, expected_shape_x)
|
|
32
|
+
self.assertEqual(y.shape, expected_shape_y)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
if __name__ == "__main__":
|
|
36
|
+
unittest.main()
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import tempfile
|
|
3
|
+
import unittest
|
|
4
|
+
from glob import glob
|
|
5
|
+
from shutil import rmtree
|
|
6
|
+
|
|
7
|
+
import tifffile
|
|
8
|
+
import numpy as np
|
|
9
|
+
from torch_em.util.test import create_image_collection_test_data
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TestImageCollectionDataset(unittest.TestCase):
|
|
13
|
+
folder = "./data"
|
|
14
|
+
n_images = 10
|
|
15
|
+
|
|
16
|
+
def setUp(self):
|
|
17
|
+
create_image_collection_test_data(self.folder,
|
|
18
|
+
n_images=self.n_images,
|
|
19
|
+
min_shape=(256, 256),
|
|
20
|
+
max_shape=(512, 512))
|
|
21
|
+
|
|
22
|
+
def tearDown(self):
|
|
23
|
+
rmtree(self.folder, ignore_errors=True)
|
|
24
|
+
|
|
25
|
+
def test_dataset(self):
|
|
26
|
+
from torch_em.data import ImageCollectionDataset
|
|
27
|
+
patch_shape = (256, 256)
|
|
28
|
+
|
|
29
|
+
raw_paths = glob(os.path.join(self.folder, "images", "*.tif"))
|
|
30
|
+
label_paths = glob(os.path.join(self.folder, "labels", "*.tif"))
|
|
31
|
+
ds = ImageCollectionDataset(raw_paths, label_paths,
|
|
32
|
+
patch_shape=patch_shape)
|
|
33
|
+
self.assertEqual(len(ds), self.n_images)
|
|
34
|
+
self.assertEqual(ds._ndim, 2)
|
|
35
|
+
|
|
36
|
+
expected_shape = (1,) + patch_shape
|
|
37
|
+
for i in range(10):
|
|
38
|
+
x, y = ds[i]
|
|
39
|
+
self.assertEqual(x.shape, expected_shape)
|
|
40
|
+
self.assertEqual(y.shape, expected_shape)
|
|
41
|
+
|
|
42
|
+
def test_dataset_with_sampler(self):
|
|
43
|
+
from torch_em.data import ImageCollectionDataset
|
|
44
|
+
from torch_em.data.sampler import MinIntensitySampler
|
|
45
|
+
patch_shape = (256, 256)
|
|
46
|
+
|
|
47
|
+
raw_paths = glob(os.path.join(self.folder, "images", "*.tif"))
|
|
48
|
+
label_paths = glob(os.path.join(self.folder, "labels", "*.tif"))
|
|
49
|
+
sampler = MinIntensitySampler(min_intensity=0.51, p_reject=0.9)
|
|
50
|
+
ds = ImageCollectionDataset(raw_paths, label_paths,
|
|
51
|
+
patch_shape=patch_shape,
|
|
52
|
+
sampler=sampler)
|
|
53
|
+
self.assertEqual(len(ds), self.n_images)
|
|
54
|
+
self.assertEqual(ds._ndim, 2)
|
|
55
|
+
|
|
56
|
+
expected_shape = (1,) + patch_shape
|
|
57
|
+
for i in range(10):
|
|
58
|
+
x, y = ds[i]
|
|
59
|
+
self.assertEqual(x.shape, expected_shape)
|
|
60
|
+
self.assertEqual(y.shape, expected_shape)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def generate_sample_data(folder, n_images, image_shape, label_shape):
|
|
64
|
+
im_folder = os.path.join(folder, "images")
|
|
65
|
+
label_folder = os.path.join(folder, "labels")
|
|
66
|
+
os.makedirs(im_folder)
|
|
67
|
+
os.makedirs(label_folder)
|
|
68
|
+
for i in range(n_images):
|
|
69
|
+
raw = np.empty(image_shape, dtype=np.uint8)
|
|
70
|
+
label = np.ones(label_shape, dtype=np.float32)
|
|
71
|
+
tifffile.imwrite(os.path.join(im_folder, f"test_{i}.tif"), raw)
|
|
72
|
+
tifffile.imwrite(os.path.join(label_folder, f"test_{i}.tif"), label)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class TestImageCollectionDatasetWithChannels(unittest.TestCase):
|
|
76
|
+
def test_channel_end(self):
|
|
77
|
+
from torch_em.data import ImageCollectionDataset
|
|
78
|
+
|
|
79
|
+
patch_shape = (256, 256)
|
|
80
|
+
|
|
81
|
+
with tempfile.TemporaryDirectory() as td:
|
|
82
|
+
generate_sample_data(td, 10, (256, 256, 2), (256, 256))
|
|
83
|
+
raw_paths = glob(os.path.join(td, "images", "*.tif"))
|
|
84
|
+
label_paths = glob(os.path.join(td, "labels", "*.tif"))
|
|
85
|
+
|
|
86
|
+
ds = ImageCollectionDataset(raw_paths, label_paths,
|
|
87
|
+
patch_shape=patch_shape)
|
|
88
|
+
self.assertEqual(len(ds), 10)
|
|
89
|
+
self.assertEqual(ds._get_sample(0)[0].shape[0], 2)
|
|
90
|
+
|
|
91
|
+
def test_channel_begin(self):
|
|
92
|
+
from torch_em.data import ImageCollectionDataset
|
|
93
|
+
|
|
94
|
+
patch_shape = (256, 256)
|
|
95
|
+
|
|
96
|
+
with tempfile.TemporaryDirectory() as td:
|
|
97
|
+
generate_sample_data(td, 10, (2, 256, 256), (256, 256))
|
|
98
|
+
raw_paths = glob(os.path.join(td, "images", "*.tif"))
|
|
99
|
+
label_paths = glob(os.path.join(td, "labels", "*.tif"))
|
|
100
|
+
|
|
101
|
+
ds = ImageCollectionDataset(raw_paths, label_paths,
|
|
102
|
+
patch_shape=patch_shape)
|
|
103
|
+
self.assertEqual(len(ds), 10)
|
|
104
|
+
self.assertEqual(ds._get_sample(0)[0].shape[0], 2)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
if __name__ == "__main__":
|
|
108
|
+
unittest.main()
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import unittest
|
|
3
|
+
|
|
4
|
+
import h5py
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
from torch_em.data.raw_dataset import RawDataset, RawDatasetWithMasks
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TestRawDatasetBase:
|
|
11
|
+
"""Base class to hold shared tests for RawDataset and subclasses."""
|
|
12
|
+
|
|
13
|
+
path = "./data.h5"
|
|
14
|
+
dataset_class = None
|
|
15
|
+
|
|
16
|
+
def tearDown(self):
|
|
17
|
+
os.remove(self.path)
|
|
18
|
+
|
|
19
|
+
def create_default_data(self, key, shape=None, chunks=None):
|
|
20
|
+
shape = (128,) * 3 if shape is None else shape
|
|
21
|
+
chunks = tuple(min(32, sh) for sh in shape) if chunks is None else chunks
|
|
22
|
+
with h5py.File(self.path, "a") as f:
|
|
23
|
+
f.create_dataset(key, data=np.random.rand(*shape), chunks=chunks)
|
|
24
|
+
return shape, chunks
|
|
25
|
+
|
|
26
|
+
def test_dataset_3d(self):
|
|
27
|
+
raw_key = "raw"
|
|
28
|
+
shape, chunks = self.create_default_data(raw_key)
|
|
29
|
+
patch_shape = chunks
|
|
30
|
+
ds = self.dataset_class(self.path, raw_key, patch_shape=patch_shape)
|
|
31
|
+
self.assertEqual(ds.raw.shape, shape)
|
|
32
|
+
self.assertEqual(ds._ndim, 3)
|
|
33
|
+
expected_shape = (1,) + patch_shape
|
|
34
|
+
for i in range(10):
|
|
35
|
+
self.assertEqual(ds[i].shape, expected_shape)
|
|
36
|
+
|
|
37
|
+
def test_dataset_2d(self):
|
|
38
|
+
raw_key = "raw"
|
|
39
|
+
shape, chunks = self.create_default_data(raw_key)
|
|
40
|
+
patch_shape = (1, 32, 32)
|
|
41
|
+
ds = self.dataset_class(self.path, raw_key, patch_shape=patch_shape, ndim=2)
|
|
42
|
+
self.assertEqual(ds.raw.shape, shape)
|
|
43
|
+
self.assertEqual(ds._ndim, 2)
|
|
44
|
+
expected_shape = patch_shape
|
|
45
|
+
for i in range(10):
|
|
46
|
+
self.assertEqual(ds[i].shape, expected_shape)
|
|
47
|
+
|
|
48
|
+
def test_dataset_4d(self):
|
|
49
|
+
raw_key = "raw"
|
|
50
|
+
shape = (12, 64, 64, 64)
|
|
51
|
+
self.create_default_data(raw_key, shape=shape)
|
|
52
|
+
patch_shape = (3, 32, 32, 32)
|
|
53
|
+
ds = self.dataset_class(self.path, raw_key, patch_shape=patch_shape)
|
|
54
|
+
self.assertEqual(ds.raw.shape, shape)
|
|
55
|
+
self.assertEqual(ds._ndim, 4)
|
|
56
|
+
expected_shape = patch_shape
|
|
57
|
+
for i in range(10):
|
|
58
|
+
self.assertEqual(ds[i].shape, expected_shape)
|
|
59
|
+
|
|
60
|
+
def test_roi(self):
|
|
61
|
+
raw_key = "raw"
|
|
62
|
+
self.create_default_data(raw_key)
|
|
63
|
+
patch_shape = (32, 32, 32)
|
|
64
|
+
roi = np.s_[32:96, 32:96, 32:96]
|
|
65
|
+
ds = self.dataset_class(self.path, raw_key, patch_shape=patch_shape, roi=roi)
|
|
66
|
+
roi_shape = 3 * (64,)
|
|
67
|
+
self.assertEqual(ds.raw.shape, roi_shape)
|
|
68
|
+
expected_shape = (1,) + patch_shape
|
|
69
|
+
for i in range(10):
|
|
70
|
+
self.assertEqual(tuple(ds[i].shape), expected_shape)
|
|
71
|
+
|
|
72
|
+
def test_with_channels(self):
|
|
73
|
+
raw_key = "raw"
|
|
74
|
+
self.create_default_data(raw_key, shape=(3, 128, 128, 128), chunks=(1, 32, 32, 32))
|
|
75
|
+
patch_shape = (32, 32, 32)
|
|
76
|
+
ds = self.dataset_class(self.path, raw_key, patch_shape=patch_shape, ndim=3, with_channels=True)
|
|
77
|
+
self.assertEqual(ds._ndim, 3)
|
|
78
|
+
expected_raw_shape = (3,) + patch_shape
|
|
79
|
+
for i in range(10):
|
|
80
|
+
self.assertEqual(ds[i].shape, expected_raw_shape)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class TestRawDataset(TestRawDatasetBase, unittest.TestCase):
|
|
84
|
+
dataset_class = RawDataset
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class TestRawDatasetWithMasks(TestRawDatasetBase, unittest.TestCase):
|
|
88
|
+
dataset_class = RawDatasetWithMasks
|
|
89
|
+
mrc_path = "./mask.mrc"
|
|
90
|
+
|
|
91
|
+
def tearDown(self):
|
|
92
|
+
super().tearDown()
|
|
93
|
+
|
|
94
|
+
if os.path.exists(self.mrc_path):
|
|
95
|
+
os.remove(self.mrc_path)
|
|
96
|
+
|
|
97
|
+
def create_default_mrc_data(self, data):
|
|
98
|
+
import mrcfile
|
|
99
|
+
with mrcfile.new(self.mrc_path, overwrite=True) as f:
|
|
100
|
+
f.set_data(data.astype(np.float32))
|
|
101
|
+
|
|
102
|
+
# subclass-specific tests, designed for a 3d dataset
|
|
103
|
+
def test_sample_mask(self):
|
|
104
|
+
from torch_em.data.sampler import MinForegroundSampler
|
|
105
|
+
|
|
106
|
+
raw_key, mask_key = "raw", "mask"
|
|
107
|
+
shape = (128, 128, 128)
|
|
108
|
+
chunks = (32, 32, 32)
|
|
109
|
+
|
|
110
|
+
# define central z slices 40:80 as the sample ROI, above and below is empty
|
|
111
|
+
sample_mask = np.zeros(shape, dtype=np.float32)
|
|
112
|
+
sample_mask[40:80, :, :] = 1.0
|
|
113
|
+
|
|
114
|
+
with h5py.File(self.path, "a") as f:
|
|
115
|
+
f.create_dataset(raw_key, data=sample_mask, chunks=chunks)
|
|
116
|
+
f.create_dataset(mask_key, data=sample_mask, chunks=chunks)
|
|
117
|
+
|
|
118
|
+
patch_shape = chunks
|
|
119
|
+
|
|
120
|
+
min_fraction = 0.95
|
|
121
|
+
sampler = MinForegroundSampler(min_fraction=min_fraction)
|
|
122
|
+
|
|
123
|
+
ds = self.dataset_class(self.path, raw_key, patch_shape=patch_shape, sampler=sampler,
|
|
124
|
+
sample_mask_path=self.path, sample_mask_key=mask_key)
|
|
125
|
+
|
|
126
|
+
self.assertEqual(ds.raw.shape, shape)
|
|
127
|
+
self.assertEqual(ds.sample_mask.shape, shape)
|
|
128
|
+
self.assertEqual(ds._ndim, 3)
|
|
129
|
+
|
|
130
|
+
expected_shape = (1,) + patch_shape
|
|
131
|
+
for i in range(10):
|
|
132
|
+
patch = ds[i]
|
|
133
|
+
self.assertEqual(patch.shape, expected_shape)
|
|
134
|
+
|
|
135
|
+
# check that patches are sampled inside the ROI defined by sample mask
|
|
136
|
+
# note that the raw data and the sample mask are identical, so this checks if the
|
|
137
|
+
# positive samples from the sample mask are correct
|
|
138
|
+
self.assertGreaterEqual(patch.mean().item(), min_fraction)
|
|
139
|
+
|
|
140
|
+
def test_bg_mask(self):
|
|
141
|
+
raw_key, mask_key = "raw", "mask"
|
|
142
|
+
|
|
143
|
+
shape, chunks = self.create_default_data(raw_key)
|
|
144
|
+
self.create_default_data(mask_key)
|
|
145
|
+
|
|
146
|
+
patch_shape = chunks
|
|
147
|
+
ds = self.dataset_class(self.path, raw_key, patch_shape=patch_shape,
|
|
148
|
+
bg_mask_path=self.path, bg_mask_key=mask_key)
|
|
149
|
+
|
|
150
|
+
self.assertEqual(ds.raw.shape, shape)
|
|
151
|
+
self.assertEqual(ds.bg_mask.shape, shape)
|
|
152
|
+
self.assertEqual(ds._ndim, 3)
|
|
153
|
+
expected_shape = (2,) + patch_shape
|
|
154
|
+
|
|
155
|
+
for i in range(10):
|
|
156
|
+
|
|
157
|
+
patch = ds[i]
|
|
158
|
+
self.assertEqual(patch.shape, expected_shape)
|
|
159
|
+
|
|
160
|
+
def test_bg_mask_mrc(self):
|
|
161
|
+
raw_key, mask_key = "raw", None
|
|
162
|
+
|
|
163
|
+
shape, chunks = self.create_default_data(raw_key)
|
|
164
|
+
self.create_default_mrc_data(np.zeros(shape))
|
|
165
|
+
|
|
166
|
+
patch_shape = chunks
|
|
167
|
+
ds = self.dataset_class(self.path, raw_key, patch_shape=patch_shape,
|
|
168
|
+
bg_mask_path=self.mrc_path, bg_mask_key=None)
|
|
169
|
+
|
|
170
|
+
self.assertEqual(ds.bg_mask.shape, shape)
|
|
171
|
+
|
|
172
|
+
if __name__ == "__main__":
|
|
173
|
+
unittest.main()
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class TestSampler(unittest.TestCase):
|
|
6
|
+
def test_min_foreground_sampler(self):
|
|
7
|
+
from torch_em.data import MinForegroundSampler
|
|
8
|
+
threshold = 0.5
|
|
9
|
+
sampler = MinForegroundSampler(min_fraction=threshold)
|
|
10
|
+
|
|
11
|
+
shape = (32, 32)
|
|
12
|
+
n_samples = 100
|
|
13
|
+
for _ in range(n_samples):
|
|
14
|
+
data = np.random.rand(*shape)
|
|
15
|
+
labels = (np.random.rand(*shape) > 0.5).astype("float32")
|
|
16
|
+
accept = sampler(data, labels)
|
|
17
|
+
expected = (labels.sum() / labels.size) > threshold
|
|
18
|
+
self.assertEqual(accept, expected)
|
|
19
|
+
|
|
20
|
+
def test_min_intensity_sampler(self):
|
|
21
|
+
from torch_em.data import MinIntensitySampler
|
|
22
|
+
threshold = 0.5
|
|
23
|
+
sampler = MinIntensitySampler(min_intensity=threshold)
|
|
24
|
+
shape = (32, 32)
|
|
25
|
+
|
|
26
|
+
n_samples = 100
|
|
27
|
+
for _ in range(n_samples):
|
|
28
|
+
data = np.random.rand(*shape)
|
|
29
|
+
accept = sampler(data)
|
|
30
|
+
expected = np.median(data) > threshold
|
|
31
|
+
self.assertEqual(accept, expected)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
if __name__ == "__main__":
|
|
35
|
+
unittest.main()
|