Skip to content

Commit

Permalink
resolves unused variables (Project-MONAI#436)
Browse files Browse the repository at this point in the history
* resolves unused variables

* fixes issue: 'torch' is imported with both 'import' and 'import from'

* less strict check in tests/test_simulatedelayd.py for crossplatform unit testing
  • Loading branch information
wyli authored May 26, 2020
1 parent ea48e78 commit 10211f9
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def prepare_batch(batch, device=None, non_blocking=False):
val_loader = DataLoader(val_ds, batch_size=2, num_workers=4, pin_memory=torch.cuda.is_available())

state = evaluator.run(val_loader)
print(state)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def prepare_batch(batch, device=None, non_blocking=False):
val_loader = DataLoader(val_ds, batch_size=2, num_workers=4, pin_memory=torch.cuda.is_available())

state = evaluator.run(val_loader)
print(state)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def run_validation(engine):

train_epochs = 30
state = trainer.run(train_loader, train_epochs)
print(state)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def run_validation(engine):

train_epochs = 30
state = trainer.run(train_loader, train_epochs)
print(state)


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions examples/segmentation_3d_ignite/unet_evaluation_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def _sliding_window_processor(engine, batch):
# sliding window inference for one image at every iteration
loader = DataLoader(ds, batch_size=1, num_workers=1, pin_memory=torch.cuda.is_available())
state = evaluator.run(loader)
print(state)
shutil.rmtree(tempdir)


Expand Down
1 change: 1 addition & 0 deletions examples/segmentation_3d_ignite/unet_evaluation_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def _sliding_window_processor(engine, batch):
val_ds, batch_size=1, num_workers=4, collate_fn=list_data_collate, pin_memory=torch.cuda.is_available()
)
state = evaluator.run(val_loader)
print(state)
shutil.rmtree(tempdir)


Expand Down
1 change: 1 addition & 0 deletions examples/segmentation_3d_ignite/unet_training_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def run_validation(engine):

train_epochs = 30
state = trainer.run(train_loader, train_epochs)
print(state)
shutil.rmtree(tempdir)


Expand Down
1 change: 1 addition & 0 deletions examples/segmentation_3d_ignite/unet_training_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def run_validation(engine):

train_epochs = 5
state = trainer.run(train_loader, train_epochs)
print(state)
shutil.rmtree(tempdir)


Expand Down
1 change: 0 additions & 1 deletion monai/metrics/rocauc.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def compute_roc_auc(y_pred, y, to_onehot_y=False, add_softmax=False, average="ma
y_pred_ndim = 1
if y_ndim == 2 and y.shape[1] == 1:
y = y.squeeze(dim=-1)
y_ndim = 1

if y_pred_ndim == 1:
if to_onehot_y:
Expand Down
11 changes: 5 additions & 6 deletions monai/visualize/img2tensorboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
import PIL
from PIL.GifImagePlugin import Image as GifImage
from torch.utils.tensorboard import SummaryWriter
from torch import Tensor
from tensorboard.compat.proto import summary_pb2
from monai.transforms.utils import rescale_array

from typing import Sequence, Union


def _image3_animated_gif(tag: str, image: Union[np.array, Tensor], scale_factor: float = 1):
def _image3_animated_gif(tag: str, image: Union[np.array, torch.Tensor], scale_factor: float = 1):
"""Function to actually create the animated gif.
Args:
tag (str): Data identifier
Expand All @@ -48,7 +47,7 @@ def _image3_animated_gif(tag: str, image: Union[np.array, Tensor], scale_factor:

def make_animated_gif_summary(
tag: str,
image: Union[np.array, Tensor],
image: Union[np.array, torch.Tensor],
max_out: int = 3,
animation_axes: Sequence[int] = (3,),
image_axes: Sequence[int] = (1, 2),
Expand Down Expand Up @@ -86,7 +85,7 @@ def make_animated_gif_summary(
image = image[tuple(slicing)]

for it_i in range(min(max_out, list(image.shape)[0])):
one_channel_img: Union[Tensor, np.array] = image[it_i, :, :, :].squeeze(dim=0) if torch.is_tensor(
one_channel_img: Union[torch.Tensor, np.array] = image[it_i, :, :, :].squeeze(dim=0) if torch.is_tensor(
image
) else image[it_i, :, :, :]
summary_op = _image3_animated_gif(tag + suffix.format(it_i), one_channel_img, scale_factor)
Expand All @@ -96,7 +95,7 @@ def make_animated_gif_summary(
def add_animated_gif(
writer: SummaryWriter,
tag: str,
image_tensor: Union[np.array, Tensor],
image_tensor: Union[np.array, torch.Tensor],
max_out: int,
scale_factor: float,
global_step: int = None,
Expand All @@ -123,7 +122,7 @@ def add_animated_gif(
def add_animated_gif_no_channels(
writer: SummaryWriter,
tag: str,
image_tensor: Union[np.array, Tensor],
image_tensor: Union[np.array, torch.Tensor],
max_out: int,
scale_factor: float,
global_step: int = None,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_simulatedelayd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_value(self, delay_test_time: float):
_ = resize({"imgd": self.imt[0]})
stop: float = time.time()
measured_approximate: float = stop - start
np.testing.assert_array_less(delay_test_time, measured_approximate)
np.testing.assert_allclose(delay_test_time, measured_approximate, rtol=1e-1)


if __name__ == "__main__":
Expand Down

0 comments on commit 10211f9

Please sign in to comment.