From e7dc28535af6060f55060656b6f5bcffe70268b1 Mon Sep 17 00:00:00 2001 From: Harrison Le Date: Fri, 4 Feb 2022 16:03:59 -0500 Subject: [PATCH 1/7] torch version change; pyproject setup --- onconet/__init__.py | 1 + pyproject.toml | 6 ++++++ requirements.txt | 4 ++-- setup.cfg | 30 ++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 pyproject.toml create mode 100644 setup.cfg diff --git a/onconet/__init__.py b/onconet/__init__.py index e69de29..3d26edf 100644 --- a/onconet/__init__.py +++ b/onconet/__init__.py @@ -0,0 +1 @@ +__version__ = "0.4.1" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f0550db --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools>=60", + "wheel" +] +build-backend = "setuptools.build_meta" diff --git a/requirements.txt b/requirements.txt index 9997ec3..3637c65 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -torch==1.4.0 -torchvision==0.2.0 +torch==1.9.0 +torchvision==0.10.0 sklearn scipy numpy diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..0618190 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,30 @@ +[metadata] +name = onconet +version = attr: onconet.__version__ +author = Adam Yala +author_email = adamyala@mit.edu +description = Sharing Deep Learning Models for Breast Cancer Risk +long_description = file: README.md +long_description_content_type = text/markdown +url = https://github.com/yala/Mirai +classifiers = + Programming Language :: Python :: 3 + License :: OSI Approved :: MIT License + +[options] +packages = find: +python_requires = >=3 +install_requires = + torch==1.9.0 + torchvision==0.10.0 + sklearn + scipy + numpy + Pillow + tqdm + mock + statsmodels + scikit-image + imageio + gitpython + lifelines From c05a9622af20831d34bd2159fe28204ba0090158 Mon Sep 17 00:00:00 2001 From: Harrison Le Date: Fri, 4 Feb 2022 16:10:51 -0500 Subject: [PATCH 2/7] dont classify `scripts` as package --- scripts/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 scripts/__init__.py diff --git a/scripts/__init__.py b/scripts/__init__.py deleted file mode 100644 index e69de29..0000000 From d7241c93218128fcdc1ef41c44951d7b4def1c79 Mon Sep 17 00:00:00 2001 From: Harrison Le Date: Fri, 4 Feb 2022 16:19:50 -0500 Subject: [PATCH 3/7] rollback torch versino for stable PR; remove unused package installation --- requirements.txt | 5 ++--- setup.cfg | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index 3637c65..1ea5ff7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,11 @@ -torch==1.9.0 -torchvision==0.10.0 +torch==1.4.0 +torchvision==0.2.0 sklearn scipy numpy Pillow tqdm mock -statsmodels scikit-image imageio gitpython diff --git a/setup.cfg b/setup.cfg index 0618190..1a6c220 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,15 +15,14 @@ classifiers = packages = find: python_requires = >=3 install_requires = - torch==1.9.0 - torchvision==0.10.0 + torch==1.4.0 + torchvision==0.2.0 sklearn scipy numpy Pillow tqdm mock - statsmodels scikit-image imageio gitpython From 1c05da068a01f452243209830510b4826c3d2d7d Mon Sep 17 00:00:00 2001 From: Harrison Le Date: Fri, 4 Feb 2022 16:36:43 -0500 Subject: [PATCH 4/7] explicitly add license file --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 1a6c220..39d6e5d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,6 +6,7 @@ author_email = adamyala@mit.edu description = Sharing Deep Learning Models for Breast Cancer Risk long_description = file: README.md long_description_content_type = text/markdown +license_files = LICENSE url = https://github.com/yala/Mirai classifiers = Programming Language :: Python :: 3 From 837b38ee1ce0f3077ddd78cbad1b12e3f4215507 Mon Sep 17 00:00:00 2001 From: Harrison Le Date: Tue, 8 Feb 2022 16:08:39 -0500 Subject: [PATCH 5/7] version freeze --- requirements.txt | 24 ++++++++++++------------ setup.cfg | 24 ++++++++++++------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1ea5ff7..172e05e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,12 @@ -torch==1.4.0 -torchvision==0.2.0 -sklearn -scipy -numpy -Pillow -tqdm -mock -scikit-image -imageio -gitpython -lifelines +gitpython==3.1.26 +imageio==2.13.1 +lifelines==0.24.15 +mock==4.0.3 +numpy==1.22.1 +Pillow==9.0.0 +scikit-image==0.18.2 +scikit-learn==0.23.2 +scipy==1.7.3 +torch==1.9.0 +torchvision==0.10.0 +tqdm==4.62.3 diff --git a/setup.cfg b/setup.cfg index 39d6e5d..5cfde03 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,15 +16,15 @@ classifiers = packages = find: python_requires = >=3 install_requires = - torch==1.4.0 - torchvision==0.2.0 - sklearn - scipy - numpy - Pillow - tqdm - mock - scikit-image - imageio - gitpython - lifelines + gitpython==3.1.26 + imageio==2.13.1 + lifelines==0.24.15 + mock==4.0.3 + numpy==1.22.1 + Pillow==9.0.0 + scikit-image==0.18.2 + scikit-learn==0.23.2 + scipy==1.7.3 + torch==1.9.0 + torchvision==0.10.0 + tqdm==4.62.3 From 4d1ba06138e2c9382ede06be7f0202ec6307e723 Mon Sep 17 00:00:00 2001 From: Viraj Kanwade Date: Tue, 25 Apr 2023 06:07:37 -0700 Subject: [PATCH 6/7] dependency version bump --- requirements-dev.txt | 2 ++ requirements.txt | 21 +++++++++------------ setup.cfg | 21 +++++++++------------ 3 files changed, 20 insertions(+), 24 deletions(-) create mode 100644 requirements-dev.txt diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..9172e0c --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,2 @@ +pytest==7.3.1 +mock==4.0.3 diff --git a/requirements.txt b/requirements.txt index 172e05e..f6e493f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,9 @@ -gitpython==3.1.26 -imageio==2.13.1 -lifelines==0.24.15 -mock==4.0.3 -numpy==1.22.1 -Pillow==9.0.0 -scikit-image==0.18.2 -scikit-learn==0.23.2 -scipy==1.7.3 -torch==1.9.0 -torchvision==0.10.0 -tqdm==4.62.3 +imageio==2.28.0 +lifelines==0.27.4 +numpy==1.24.3 +scikit-image==0.20.0 +scikit-learn==1.2.2 +scipy==1.10.1 +torch==2.0.0 +torchvision==0.15.1 +tqdm==4.65.0 diff --git a/setup.cfg b/setup.cfg index 5cfde03..c4a1f55 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,15 +16,12 @@ classifiers = packages = find: python_requires = >=3 install_requires = - gitpython==3.1.26 - imageio==2.13.1 - lifelines==0.24.15 - mock==4.0.3 - numpy==1.22.1 - Pillow==9.0.0 - scikit-image==0.18.2 - scikit-learn==0.23.2 - scipy==1.7.3 - torch==1.9.0 - torchvision==0.10.0 - tqdm==4.62.3 + imageio==2.28.0 + lifelines==0.27.4 + numpy==1.24.3 + scikit-image==0.20.0 + scikit-learn==1.2.2 + scipy==1.10.1 + torch==2.0.0 + torchvision==0.15.1 + tqdm==4.65.0 From 6ab10a7ac39f46748d50a2da63777b7f3c6c7550 Mon Sep 17 00:00:00 2001 From: Viraj Kanwade Date: Tue, 25 Apr 2023 06:52:51 -0700 Subject: [PATCH 7/7] fix unit tests --- onconet/datasets/loader/image.py | 2 +- tests/test_transformers.py | 11 ++++++----- tests/test_utils.py | 11 ++++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/onconet/datasets/loader/image.py b/onconet/datasets/loader/image.py index 32f5dba..e44498b 100644 --- a/onconet/datasets/loader/image.py +++ b/onconet/datasets/loader/image.py @@ -161,7 +161,7 @@ def get_image(self, path, additional): all_transformers = self.split_transformers[-1][1] image = Image.open(path) image = apply_transformers_and_cache(image, additional, path, all_transformers, - self.cache) + self.cache, cache_full_size=True) return image def get_images(self, paths, additionals): diff --git a/tests/test_transformers.py b/tests/test_transformers.py index f8512bf..b9c7be4 100644 --- a/tests/test_transformers.py +++ b/tests/test_transformers.py @@ -75,7 +75,8 @@ def test_image_random_crop(self): im.putdata(pixel) self.kwargs['w'] = 2 self.kwargs['h'] = 2 - with mock.patch('random.randint', lambda x, y: 0): + self.args.use_region_annotation = False + with mock.patch('torch.randint', lambda x, y, size: torch.tensor([0])): cropper = ti.Random_Crop(self.args, self.kwargs) output = cropper(im, None) expected = Image.new("RGB", (2, 2)) @@ -109,12 +110,12 @@ def test_image_rotate_90(self): def test_tensor_normalize_tensor_2d(self): ''' Test normalizing a tensor with a certain mean and a certain std deviation.''' - self.args.img_mean = 2 - self.args.img_std = 2 - tensor = torch.IntTensor([[[4, 4, 4], [6, 6, 6]], [[8, 8, 8], [10, 10, 10]]]) + self.args.img_mean = [2.0] + self.args.img_std = [2.0] + tensor = torch.FloatTensor([[[4, 4, 4], [6, 6, 6]], [[8, 8, 8], [10, 10, 10]]]) normalizer = tt.Normalize_Tensor_2d(self.args, self.kwargs) output = normalizer(tensor, None).numpy() - expected = torch.IntTensor([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]]).numpy() + expected = torch.FloatTensor([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]]).numpy() self.assertTrue(np.array_equal(expected, output)) diff --git a/tests/test_utils.py b/tests/test_utils.py index c5031bb..cf683eb 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -13,13 +13,13 @@ import onconet.utils.parsing as parsing import onconet.utils.generic as generic -import onconet.train.state_keeper as state +import onconet.learn.state_keeper as state import datetime class Test_parse_transformers(unittest.TestCase): def setUp(self): self.err_msg = "Name of transformer or one of its arguments cant be empty\n\ - Use 'name/arg1=value/arg2=value' format" + Use \"name/arg1=value/arg2=value\" format" def tearDown(self): pass @@ -238,6 +238,7 @@ def setUp(self): self.parser.add_argument('--age', default=10) self.parser.add_argument('--siblings', default=["alice", "bob"]) self.parser.add_argument('--save_dir', default=tempfile.mkdtemp()) + self.parser.add_argument('--use_adv', action='store_true', default=False) self.epoch = 10 self.lr = 0.001 self.epoch_stats = {} @@ -256,12 +257,12 @@ def test_simple_model(self): model_dict = self.model.state_dict() optimizer_dict = self.optimizer.state_dict() - state_keeper.save(self.model, self.optimizer, self.epoch, self.lr, self.epoch_stats) + state_keeper.save({'model': self.model}, {'model': self.optimizer}, self.epoch, self.lr, self.epoch_stats) new_model, new_optimizer_state, new_epoch, new_lr, _ = state_keeper.load() for key in model_dict.keys(): - self.assertTrue(np.array_equal(model_dict[key].numpy(), new_model.state_dict()[key].numpy())) - self.assertEqual(optimizer_dict, new_optimizer_state) + self.assertTrue(np.array_equal(model_dict[key].numpy(), new_model['model'].state_dict()[key].numpy())) + self.assertEqual(optimizer_dict, new_optimizer_state['model']) self.assertEqual(self.epoch, new_epoch) self.assertEqual(self.lr, new_lr)