Skip to content

Commit

Permalink
Merging
Browse files Browse the repository at this point in the history
  • Loading branch information
evsmithx committed Feb 10, 2021
2 parents 45bf722 + cb0a856 commit 8173fa7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ ENABLED:
# R0801: similar lines

[IMPORTS]
ignored-modules=aiohttp,cv2,defusedxml,imgaug,google,gym,fetch,librosa,matplotlib,
ignored-modules=aiohttp,defusedxml,imgaug,google,gym,fetch,librosa,matplotlib,
memory_profiler,numpy,oef,opacus,
openapi_core,pandas,psutil,pydantic,pytest,tensorflow,tensorflow_datasets,tensorflow_core,
openapi_core,pandas,PIL,psutil,pydantic,pytest,tensorflow,tensorflow_datasets,tensorflow_core,
tensorflow_privacy,temper,torch,torchvision,torchsummary,tqdm,typing_extensions,
scipy,skimage,sklearn,vyper,web3
12 changes: 6 additions & 6 deletions colearn_pytorch/pytorch_xray.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from glob import glob
from pathlib import Path
from typing import Tuple, Optional, List
from typing_extensions import TypedDict

import cv2
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as nn_func
from PIL import Image
from torch.utils.data import Dataset, DataLoader
from typing_extensions import TypedDict

from colearn_pytorch.pytorch_learner import PytorchLearner
from .utils import auc_from_logits
Expand Down Expand Up @@ -276,10 +276,10 @@ def to_rgb_normalize_and_resize(
:param height: Output height
:return: Resized and normalizes image as np.array
"""
img = cv2.imread(str(filename))
img = cv2.resize(img, (width, height))
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = img.astype(np.float32) / 255.
img = Image.open(str(filename))
img = img.resize((width, height))
img = img.convert('L') # convert to greyscale
img = np.array(img.getdata()).reshape((1, img.size[0], img.size[1])) / 255

return img

Expand Down
15 changes: 7 additions & 8 deletions examples/pytorch_xray.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
import tempfile
from glob import glob
from pathlib import Path
from typing_extensions import TypedDict

import numpy as np
import cv2
import torch.nn as nn
import torch.nn.functional as nn_func
import torch.utils.data
from PIL import Image
from torch.utils.data import Dataset
from torchsummary import summary
from typing_extensions import TypedDict

from colearn.training import initial_result, collective_learning_round, set_equal_weights
from colearn.utils.plot import ColearnPlot
from colearn.utils.results import Results, print_results
from colearn_pytorch.utils import auc_from_logits
from colearn_pytorch.pytorch_learner import PytorchLearner
from colearn_pytorch.utils import auc_from_logits

"""
Xray training example using Pytorch
Expand All @@ -39,7 +39,6 @@
"""


# define some constants
n_learners = 5
batch_size = 8
Expand Down Expand Up @@ -179,10 +178,10 @@ def __getitem__(self, idx):

@staticmethod
def to_rgb_normalize_and_resize(filename, width, height):
img = cv2.imread(str(filename))
img = cv2.resize(img, (width, height))
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = img.astype(np.float32) / 255.
img = Image.open(str(filename))
img = img.resize((width, height))
img = img.convert('L') # convert to greyscale
img = np.array(img.getdata()).reshape((1, img.size[0], img.size[1])) / 255

return img

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
]
pytorch_deps = [
'opacus~=0.10.0',
'opencv-python~=4.4.0',
'Pillow~=8.0.1',
'scipy~=1.5.0',
'torch~=1.7.0',
'torchsummary~=1.5.0',
Expand Down

0 comments on commit 8173fa7

Please sign in to comment.