diff --git a/.github/workflows/checks_tests_deploy.yml b/.github/workflows/checks_tests_deploy.yml index 64baca6..e91b0b6 100644 --- a/.github/workflows/checks_tests_deploy.yml +++ b/.github/workflows/checks_tests_deploy.yml @@ -45,7 +45,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools setuptools_scm pylint tox tox-gh-actions pytest pytest-coverage twine build + pip install setuptools setuptools_scm pylint==2.17.7 tox tox-gh-actions pytest pytest-coverage twine build pip install . - name: Debug Info run: | diff --git a/scripts/molmapsbbox.py b/scripts/molmapsbbox.py index 10bc97d..964d4e6 100644 --- a/scripts/molmapsbbox.py +++ b/scripts/molmapsbbox.py @@ -1,19 +1,22 @@ -from skimage.measure import label, regionprops -import numpy as np +import argparse +import json +import os from typing import List + import mrcfile +import numpy as np +import skimage.measure as skm + from tomotwin.modules.common.preprocess import label_filename -import argparse -import os -import json + def binarize(vol): t = np.max(vol) - (np.max(vol) - np.min(vol)) * 0.9 return vol > t def boxsize(vol): - lbl = label(vol, background=0) - regs = regionprops(lbl) + lbl = skm.label(vol, background=0) + regs = skm.regionprops(lbl) size = -1 for reg in regs: cand_size = np.max([np.abs(reg.bbox[i] - reg.bbox[i+3]) for i in range(int(len(reg.bbox)/2))]) diff --git a/tests/test_embed_main.py b/tests/test_embed_main.py index ea351cb..c229036 100644 --- a/tests/test_embed_main.py +++ b/tests/test_embed_main.py @@ -83,6 +83,10 @@ def test_embed_main_real_subvol_torchembeddor(self): ) @pytest.mark.skipif(torch.cuda.is_available() == False, reason="Skipped because CUDA is not available") def test_embed_main_real_subvol_distributedtorchembeddor(self): + import random + os.environ['MASTER_ADDR'] = '127.0.0.1' + os.environ['MASTER_PORT'] = '29' + str(random.randint(1, 500)).zfill(3) + from tomotwin.embed_main import run as embed_main_func tomo = np.random.randn(37, 37, 37).astype(np.float32) diff --git a/tomotwin/embed_main.py b/tomotwin/embed_main.py index 3959604..4b742b4 100644 --- a/tomotwin/embed_main.py +++ b/tomotwin/embed_main.py @@ -377,6 +377,7 @@ import glob import hashlib import os +import random import resource import sys from typing import List @@ -605,6 +606,8 @@ def run_distr(config, world_size: int): f"Your user limit ('ulimit -n') is too low ({limit[0]}). Please run 'ulimit -n 65000' before running tomotwin_embed.") sys.exit(1) print(f"Found {world_size} GPU(s). Start DDP + Compiling.") + os.environ['MASTER_ADDR'] = '127.0.0.1' + os.environ['MASTER_PORT'] = '29' + str(random.randint(1, 500)).zfill(3) mp.spawn( run, args=([config, world_size]), diff --git a/tomotwin/modules/common/io/mrc_format.py b/tomotwin/modules/common/io/mrc_format.py index 73d458e..3725cb6 100644 --- a/tomotwin/modules/common/io/mrc_format.py +++ b/tomotwin/modules/common/io/mrc_format.py @@ -381,8 +381,10 @@ class MrcFormat: @staticmethod def read(pth: str) -> np.array: + vol = None try: - vol = mrcfile.open(pth, mode="r", permissive=True) + with mrcfile.open(pth, mode="r", permissive=True) as mrc: + vol = mrc.data except ValueError as e: raise Exception(f"Failed reading {pth}") from e - return vol.data + return vol diff --git a/tomotwin/modules/inference/embedor.py b/tomotwin/modules/inference/embedor.py index 6af09f3..b0b7d62 100644 --- a/tomotwin/modules/inference/embedor.py +++ b/tomotwin/modules/inference/embedor.py @@ -375,7 +375,6 @@ defined by the Mozilla Public License, v. 2.0. """ -import os from abc import ABC, abstractmethod import numpy as np @@ -522,9 +521,6 @@ def __init__( workers: int = 0, ) -> None: """Inits the embedor""" - - os.environ['MASTER_ADDR'] = '127.0.0.1' - os.environ['MASTER_PORT'] = '29500' tdist.init_process_group(backend='gloo', rank=rank, world_size=world_size) tdist.barrier() self.rank = rank diff --git a/tomotwin/modules/networks/SiameseNet3D.py b/tomotwin/modules/networks/SiameseNet3D.py index 876f753..28e739f 100644 --- a/tomotwin/modules/networks/SiameseNet3D.py +++ b/tomotwin/modules/networks/SiameseNet3D.py @@ -524,8 +524,7 @@ def forward(self, inputtensor): Forward pass through the network :param inputtensor: Input tensor """ - - inputtensor = nn.functional.pad(inputtensor, (1, 2, 1, 2, 1, 2)) + inputtensor = F.pad(inputtensor, (1, 2, 1, 2, 1, 2)) out = self.conv_layer0(inputtensor) out = self.max_pooling(out)