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

Added some peices of miccai2015 dataset. #124

Merged
merged 4 commits into from
Oct 28, 2022
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
2 changes: 2 additions & 0 deletions nndt/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from .acdc import ACDC
from .miccai2015 import MICCAI2015
from .utils import *

list_of_datasets = [
"ACDC",
"MICCAI2015",
]

source_url = "https://github.com/KonstantinUshenin/nndt"
17 changes: 7 additions & 10 deletions nndt/datasets/acdc.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from nndt.datasets.dataset import dataset
from nndt.datasets.dataset import Dataset


class ACDC(dataset):
class ACDC(Dataset):
def __init__(self, name="ACDC_5", to_path=None):
super().__init__()
super().__init__(name=name, to_path=to_path)

__dict = {
self._dict = {
"ACDC_5": [
[
"https://drive.google.com/file/d/1UzC2WPkjMQSxzI5sj1rMT47URuZbQhYb/view?usp=sharing",
Expand Down Expand Up @@ -36,17 +36,14 @@ def __init__(self, name="ACDC_5", to_path=None):
],
}

if name in __dict.keys():
if name in self._dict.keys():
if "test" in name:
self.name = "ACDC_5"
else:
self.name = name
self.to_path = to_path
self.urls, self.hash = __dict[name]
self.urls, self.hash = self._dict[name]
else:
raise ValueError(
f'name must be in {[key for key in __dict if "test" not in key]}'
f'name must be in {[key for key in self._dict if "_test" not in key]}'
)

def load(self):
super(ACDC, self).load()
11 changes: 8 additions & 3 deletions nndt/datasets/dataset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import warnings
from pathlib import Path

from nndt import datasets
Expand All @@ -10,12 +11,16 @@
)


class dataset:
class Dataset:
def __init__(self, name=None, to_path=None):
self.name = name
self.to_path = to_path
self.hash = None
self.urls = None
self._dict = None

def dataset_list(self):
return [key for key in self._dict if "_test" not in key]

def load(self) -> None:

Expand All @@ -32,7 +37,7 @@ def load(self) -> None:
assert _check_md5(z, self.hash)
_extract_7z_file(z, self.to_path)
except Exception as e:
Dopervigest marked this conversation as resolved.
Show resolved Hide resolved
print(url, str(e))
warnings.warn(str(e))
continue
else:
try:
Expand All @@ -41,7 +46,7 @@ def load(self) -> None:
assert _check_md5(z, self.hash)
_extract_7z_file(z, self.to_path)
except Exception as e:
print(url, str(e))
warnings.warn(str(e))
continue
complete = True
os.remove(z)
Expand Down
56 changes: 56 additions & 0 deletions nndt/datasets/miccai2015.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from nndt.datasets.dataset import Dataset


class MICCAI2015(Dataset):
def __init__(self, name="left_adrenal_gland_10", to_path=None):
super().__init__(name=name, to_path=to_path)

self._dict = {
"left_adrenal_gland_10": [
[
"https://drive.google.com/file/d/1LFJs5tW-acZOXTVVHh-WpWRNkAgtKaDd/view?usp=sharing",
"https://www.dropbox.com/s/xyarraopmj069de/left_adrenal_gland.7z?raw=1",
],
"03c5f5c7e33a57ed71f497725d6925db",
],
"stomach_10": [
[
"https://drive.google.com/file/d/189tTsVX89qUijClkPkZfBiX5hRMupW03/view?usp=sharing",
"https://www.dropbox.com/s/uzhurjucqqnansh/stomach.7z?raw=1",
],
"3a7a817748c43194fa75b1e5ab798d56",
],
"wrong_url_test": [
[
"https://drive.google.com/file",
"a",
"b",
"https://a.com",
"https://www.dropbox.com/s/m",
],
"03c5f5c7e33a57ed71f497725d6925db",
],
"wrong_hash_test": [
[
"https://drive.google.com/file/d/1UzC2WPkjMQSxzI5sj1rMT47URuZbQhYb/view?usp=sharing",
"https://www.dropbox.com/s/6fomqxbjs0iu79m/ACDC_5.7z?raw=1",
],
"34d007546353673899c73337d38c9c12 ",
],
"dropbox_test": [
[
"https://www.dropbox.com/s/xyarraopmj069de/left_adrenal_gland.7z?raw=1"
],
"03c5f5c7e33a57ed71f497725d6925db",
],
}

if name in self._dict.keys():
self.name = "MICCAI2015"
self.to_path = to_path
self.urls, self.hash = self._dict[name]

else:
raise ValueError(
f'name must be in {[key for key in self._dict if "_test" not in key]}'
)
8 changes: 7 additions & 1 deletion tests/test_load_datasets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import shutil

from nndt.datasets import ACDC
from nndt.datasets import ACDC, MICCAI2015
from tests.base import BaseTestCase

DATASETS_FOLDER = ".datasets"
Expand Down Expand Up @@ -38,3 +38,9 @@ def test_random_name(self):
def test_wrong_hash(self):
with self.assertRaises(ConnectionError):
ACDC("wrong_hash_test").load()

def test_dataset_list(self):
_list = MICCAI2015().dataset_list()
self.assertTrue(_list is not None)
self.assertTrue(len(_list) > 0)
self.assertTrue(len([item for item in _list if "_test" in item]) == 0)