Commit 68352e5c authored by Baumgartner, Michael's avatar Baumgartner, Michael
Browse files

Merge branch '0002_cleanup' into main

parents 8607cb0f 9ef2a30d
......@@ -32,7 +32,6 @@ from nndet.utils.info import experimental
class FROCMetric(DetectionMetric):
@experimental
def __init__(self,
classes: Sequence[str],
iou_thresholds: Sequence[float] = (0.1, 0.5),
......
"""
Some parts are adapted from https://github.com/cocodataset/cocoapi :
Copyright (c) 2014, Piotr Dollar and Tsung-Yi Lin
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
"""
"""
For the remaining parts:
Copyright 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
# Modifications licensed under:
# SPDX-FileCopyrightText: 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany
# SPDX-License-Identifier: Apache-2.0
#
# Parts of this code are from cocoapi licensed under
# SPDX-FileCopyrightText: 2014, Piotr Dollar and Tsung-Yi Lin
# SPDX-License-Identifier: BSD-2-Clause-Views
import numpy as np
from typing import Callable, Sequence, List, Dict
......
......@@ -190,8 +190,8 @@ def get_instance_class_from_properties(
Returns:
Tensor: extracted instance classes
"""
instance_idx, _ = instance_idx.sort()
classes = [int(map_dict[str(int(idx.detach().item()))]) for idx in instance_idx]
_map_dict = {int(k): int(i) for k, i in map_dict.items()}
classes = [int(_map_dict[int(idx.detach().item())]) for idx in instance_idx]
return torch.tensor(classes, device=instance_idx.device)
......@@ -207,8 +207,8 @@ def get_instance_class_from_properties_seq(
Returns:
Sequence[int]: extracted instance classes
"""
instance_idx = sorted(instance_idx)
classes = [int(map_dict[str(int(idx))]) for idx in instance_idx]
_map_dict = {int(k): int(i) for k, i in map_dict.items()}
classes = [int(_map_dict[int(idx)]) for idx in instance_idx]
return classes
......
# Modifications licensed under:
# SPDX-FileCopyrightText: 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany
# SPDX-License-Identifier: Apache-2.0
#
# L1 loss from fvcore (https://github.com/facebookresearch/fvcore) licensed under
# SPDX-FileCopyrightText: 2019, Facebook, Inc
# SPDX-License-Identifier: Apache-2.0
from typing import Optional
import torch
......
# SPDX-FileCopyrightText: 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany
# SPDX-License-Identifier: Apache-2.0
import functools
import os
import warnings
......@@ -264,7 +268,7 @@ def _full_check(
def _check_itk_params(
img_seq: Sequence[sitk.Image],
paths: Sequence[Path],
) -> None:
) -> None:
"""
Check Dimension, Origin, Direction and Spacing of a Sequence of images
......@@ -279,15 +283,31 @@ def _check_itk_params(
ValueError: raised if spacing does not match
"""
for idx, img in enumerate(img_seq[1:], start=1):
if not (np.asarray(img_seq[0].GetDimension()) == \
np.asarray(img.GetDimension())).all():
raise ValueError(f"Expected {paths[idx]} and {paths[0]} to have same dimensions!")
if not (np.asarray(img_seq[0].GetOrigin()) == \
np.asarray(img.GetOrigin())).all():
raise ValueError(f"Expected {paths[idx]} and {paths[0]} to have same origin!")
if not (np.asarray(img_seq[0].GetDirection()) == \
np.asarray(img.GetDirection())).all():
raise ValueError(f"Expected {paths[idx]} and {paths[0]} to have same direction!")
if not (np.asarray(img_seq[0].GetSpacing()) == \
np.asarray(img.GetSpacing())).all():
raise ValueError(f"Expected {paths[idx]} and {paths[0]} to have same spacing!")
if not (
np.asarray(img_seq[0].GetDimension()) == np.asarray(img.GetDimension())
).all():
raise ValueError(
f"Expected {paths[idx]} and {paths[0]} to have same dimensions!"
)
if not ((np.asarray(img_seq[0].GetSize()) == np.asarray(img.GetSize()))).all():
raise ValueError(
f"Expected {paths[idx]} and {paths[0]} to have same dimensions!"
)
if not np.allclose(
np.asarray(img_seq[0].GetOrigin()), np.asarray(img.GetOrigin())
):
raise ValueError(
f"Expected {paths[idx]} and {paths[0]} to have same origin!"
)
if not np.allclose(
np.asarray(img_seq[0].GetDirection()), np.asarray(img.GetDirection())
):
raise ValueError(
f"Expected {paths[idx]} and {paths[0]} to have same direction!"
)
if not np.allclose(
np.asarray(img_seq[0].GetSpacing()), np.asarray(img.GetSpacing())
):
raise ValueError(
f"Expected {paths[idx]} and {paths[0]} to have same spacing!"
)
# Modifications licensed under:
# SPDX-FileCopyrightText: 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany
# SPDX-License-Identifier: Apache-2.0
#
# L1 loss from fvcore (https://github.com/facebookresearch/fvcore) licensed under
# SPDX-FileCopyrightText: 2019, Facebook, Inc
# SPDX-License-Identifier: Apache-2.0
import inspect
import shutil
import os
......
# SPDX-FileCopyrightText: 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany
# SPDX-License-Identifier: Apache-2.0
from collections import defaultdict
import torch
......
# SPDX-FileCopyrightText: 2020 Division of Medical Image Computing, German Cancer Research Center (DKFZ), Heidelberg, Germany
# SPDX-License-Identifier: Apache-2.0
import time
from loguru import logger
......
......@@ -177,7 +177,7 @@ def _train(
do_sweep: determine best emprical parameters for run
"""
print(f"Overwrites: {ov}")
initialize_config_module(config_module="nndet.conf")
initialize_config_module(config_module="nndet.conf", version_base="1.1")
cfg = compose(task, "config.yaml", overrides=ov if ov is not None else [])
assert cfg.host.parent_data is not None, 'Parent data can not be None'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment