Skip to content

Commit 17528af

Browse files
authored
Merge pull request #92 from ziatdinovmax/master
Bump up to Numpy 2.0
2 parents 8db3e94 + ac22e23 commit 17528af

File tree

8 files changed

+22
-21
lines changed

8 files changed

+22
-21
lines changed

.github/workflows/actions.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: build
22

33
env:
4-
PYTHON_MAIN_VERSION: 3.8
4+
PYTHON_MAIN_VERSION: 3.10
55

66
on:
77
pull_request:
@@ -19,7 +19,7 @@ jobs:
1919
strategy:
2020
max-parallel: 5
2121
matrix:
22-
python-version: [3.8, 3.9]
22+
python-version: ["3.9", "3.10", "3.11"]
2323

2424
steps:
2525
- uses: actions/checkout@v2

atomai/models/dgm/vae.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ def manifold2d(self, **kwargs: Union[int, List, str, bool]) -> None: # use torc
434434
figure[i * self.in_dim[0]: (i + 1) * self.in_dim[0],
435435
j * self.in_dim[1]: (j + 1) * self.in_dim[1]] = imdec
436436
if figure.min() < 0:
437-
figure = (figure - figure.min()) / figure.ptp()
437+
figure = (figure - figure.min()) / np.ptp(figure)
438438

439439
fig, ax = plt.subplots(figsize=(10, 10))
440440
ax.imshow(figure, cmap=cmap, origin=kwargs.get("origin", "lower"),
@@ -506,7 +506,7 @@ def manifold_traversal(self, cont_idx: int,
506506
grid = make_grid(torch.from_numpy(decoded),
507507
nrow=d, padding=kwargs.get("pad", 2)).numpy()
508508
grid = grid.transpose(1, 2, 0) if len(self.in_dim) == 3 else grid[0]
509-
grid = (grid - grid.min()) / grid.ptp()
509+
grid = (grid - grid.min()) / np.ptp(grid)
510510
if not kwargs.get("keep_square", False) and disc_dim != d:
511511
grid = grid[:(self.in_dim[0]+kwargs.get("pad", 2)) * disc_dim]
512512
if plot:

atomai/models/loaders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def load_model(filepath: str) -> Union[Segmentor, Union[VAE, rVAE, jrVAE, jVAE],
3434
Model in evaluation state
3535
"""
3636
device = 'cuda' if torch.cuda.is_available() else 'cpu'
37-
loaded_dict = torch.load(filepath, map_location=device)
37+
loaded_dict = torch.load(filepath, map_location=device, weights_only=False)
3838
if 'model_type' in loaded_dict.keys():
3939
model_type = loaded_dict.pop("model_type")
4040
with warnings.catch_warnings():

atomai/nets/ed.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(self, signal_dim: Tuple[int],
5656
bn = kwargs.get('batch_norm', True)
5757
if self.downsample:
5858
signal_dim = [s // self.downsample for s in signal_dim]
59-
n = np.product(signal_dim)
59+
n = np.prod(signal_dim)
6060
self.reshape_ = nb_filters * n
6161
self.conv = ConvBlock(
6262
ndim, nb_layers, 1, nb_filters,
@@ -118,7 +118,7 @@ def __init__(self, signal_dim: Tuple[int],
118118
ndim = 2 if len(signal_dim) == 2 else 1
119119
if self.upsampling:
120120
signal_dim = [s // 4 for s in signal_dim]
121-
n = np.product(signal_dim)
121+
n = np.prod(signal_dim)
122122
self.reshape_ = (nb_filters, *signal_dim)
123123
self.fc = nn.Linear(z_dim, nb_filters*n)
124124
if self.upsampling:
@@ -269,7 +269,7 @@ def __init__(self,
269269
self.conv = ConvBlock(
270270
dim, num_layers, c, hidden_dim,
271271
lrelu_a=kwargs.get("lrelu_a", 0.1))
272-
self.reshape_ = hidden_dim * np.product(in_dim[:2])
272+
self.reshape_ = hidden_dim * np.prod(in_dim[:2])
273273
self.fc11 = nn.Linear(self.reshape_, latent_dim)
274274
self.fc12 = nn.Linear(self.reshape_, latent_dim)
275275
self._out = nn.Softplus() if kwargs.get("softplus_out") else lambda x: x
@@ -323,7 +323,7 @@ def __init__(self,
323323
super(fcEncoderNet, self).__init__()
324324
dense = []
325325
for i in range(num_layers):
326-
input_dim = np.product(in_dim) if i == 0 else hidden_dim
326+
input_dim = np.prod(in_dim) if i == 0 else hidden_dim
327327
dense.extend([nn.Linear(input_dim, hidden_dim), nn.Tanh()])
328328
self.dense = nn.Sequential(*dense)
329329
self.reshape_ = hidden_dim
@@ -335,7 +335,7 @@ def forward(self, x: torch.Tensor):
335335
"""
336336
Forward pass
337337
"""
338-
x = x.reshape(-1, np.product(x.size()[1:]))
338+
x = x.reshape(-1, np.prod(x.size()[1:]))
339339
x = self.dense(x)
340340
x = x.reshape(-1, self.reshape_)
341341
z_mu = self.fc11(x)
@@ -378,7 +378,7 @@ def __init__(self,
378378
super(jfcEncoderNet, self).__init__()
379379
dense = []
380380
for i in range(num_layers):
381-
input_dim = np.product(in_dim) if i == 0 else hidden_dim
381+
input_dim = np.prod(in_dim) if i == 0 else hidden_dim
382382
dense.extend([nn.Linear(input_dim, hidden_dim), nn.Tanh()])
383383
self.dense = nn.Sequential(*dense)
384384
self.reshape_ = hidden_dim
@@ -394,7 +394,7 @@ def forward(self, x: torch.Tensor):
394394
"""
395395
Forward pass
396396
"""
397-
x = x.reshape(-1, np.product(x.size()[1:]))
397+
x = x.reshape(-1, np.prod(x.size()[1:]))
398398
x = self.dense(x)
399399
x = x.reshape(-1, self.reshape_)
400400
encoded = [self.fc11(x), self._out(self.fc12(x))]
@@ -446,7 +446,7 @@ def __init__(self,
446446
self.conv = ConvBlock(
447447
dim, num_layers, c, hidden_dim,
448448
lrelu_a=kwargs.get("lrelu_a", 0.1))
449-
self.reshape_ = hidden_dim * np.product(in_dim[:2])
449+
self.reshape_ = hidden_dim * np.prod(in_dim[:2])
450450
self.fc11 = nn.Linear(self.reshape_, latent_dim)
451451
self.fc12 = nn.Linear(self.reshape_, latent_dim)
452452
fc13 = []
@@ -501,7 +501,7 @@ def __init__(self,
501501
dim = 2 if len(out_dim) > 1 else 1
502502
c = out_dim[-1] if len(out_dim) > 2 else 1
503503
self.fc_linear = nn.Linear(
504-
latent_dim, hidden_dim * np.product(out_dim[:2]),
504+
latent_dim, hidden_dim * np.prod(out_dim[:2]),
505505
bias=False)
506506
self.reshape_ = (hidden_dim, *out_dim[:2])
507507
self.decoder = ConvBlock(
@@ -563,7 +563,7 @@ def __init__(self,
563563
hidden_dim_ = latent_dim if i == 0 else hidden_dim
564564
decoder.extend([nn.Linear(hidden_dim_, hidden_dim), nn.Tanh()])
565565
self.decoder = nn.Sequential(*decoder)
566-
self.out = nn.Linear(hidden_dim, np.product(out_dim))
566+
self.out = nn.Linear(hidden_dim, np.prod(out_dim))
567567
self.out_dim = (c, *out_dim[:2])
568568

569569
def forward(self, z: torch.Tensor) -> torch.Tensor:

atomai/predictors/predictor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ def run(self,
286286
return decoded_imgs
287287
images, decoded_imgs = self.predict(
288288
image_data, return_image=True, **kwargs)
289-
loc = Locator(self.thresh, refine=self.refine, d=self.d)
289+
thresh = kwargs.get("thresh", self.thresh)
290+
loc = Locator(thresh, refine=self.refine, d=self.d)
290291
coordinates = loc.run(decoded_imgs, images)
291292
if self.verbose:
292293
n_images_str = " image was " if decoded_imgs.shape[0] == 1 else " images were "

atomai/transforms/imaug.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def run(self, images: np.ndarray, targets: np.ndarray) -> Tuple[np.ndarray]:
319319
pass
320320
else:
321321
raise NotImplementedError("Use 'channel_first' or 'channel_last'")
322-
images = (images - images.min()) / images.ptp()
322+
images = (images - images.min()) / np.ptp(images)
323323
if self.custom_transform is not None:
324324
images, targets = self.custom_transform(images, targets)
325325
if self.rotation and same_dim:
@@ -354,7 +354,7 @@ def run(self, images: np.ndarray, targets: np.ndarray) -> Tuple[np.ndarray]:
354354
images = np.expand_dims(images, axis=3)
355355
else:
356356
raise NotImplementedError("Use 'channel_first' or 'channel_last'")
357-
images = (images - images.min()) / images.ptp()
357+
images = (images - images.min()) / np.ptp(images)
358358
return images, targets
359359

360360

atomai/utils/preproc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ def torch_format_image(image_data: np.ndarray,
757757
else:
758758
pass
759759
if norm:
760-
image_data = (image_data - image_data.min()) / image_data.ptp()
760+
image_data = (image_data - image_data.min()) / np.ptp(image_data)
761761
image_data = torch.from_numpy(image_data).float()
762762
return image_data
763763

@@ -786,7 +786,7 @@ def torch_format_spectra(spectra: np.ndarray,
786786
else:
787787
pass
788788
if norm:
789-
spectra = (spectra - spectra.min()) / spectra.ptp()
789+
spectra = (spectra - spectra.min()) / np.ptp(spectra)
790790
spectra = torch.from_numpy(spectra).float()
791791
return spectra
792792

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ opencv-python>=4.1.0
1212
networkx>=2.5
1313
mendeleev<=0.6.1
1414
progressbar2>=3.38.0
15-
gpytorch>=1.4.0,<1.7.0
15+
gpytorch>=1.9.1

0 commit comments

Comments
 (0)