Skip to content

Commit

Permalink
📌 Updates dependencies. Removes TF, Keras now uses Pytorch as backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
amarrerod committed Sep 11, 2024
1 parent 17f9b88 commit 43cdafd
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 29 deletions.
14 changes: 11 additions & 3 deletions digneapy/transformers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@

import os

os.environ["KERAS_BACKEND"] = "torch"

from digneapy.transformers.autoencoders import KPAE, KPAE50
from digneapy.transformers.base import SupportsTransform, Transformer
from digneapy.transformers.keras_nn import KerasNN
from digneapy.transformers.torch_nn import TorchNN
from digneapy.transformers.tuner import NNTuner

os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"

__all__ = ["Transformer", "SupportsTransform", "KerasNN", "TorchNN", "NNTuner", "KPAE", "KPAE50"]
__all__ = [
"Transformer",
"SupportsTransform",
"KerasNN",
"TorchNN",
"NNTuner",
"KPAE",
"KPAE50",
]
16 changes: 12 additions & 4 deletions digneapy/transformers/autoencoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,19 @@ def decode(self, X: npt.NDArray) -> np.ndarray:
def __call__(self, X: npt.NDArray) -> np.ndarray:
return self.encode(X)


class KPAE50(KPAE):
def __init__(self):
super().__init__("KPAE50", 2, False)
self._model = keras.models.load_model(f"{KPAE._MODELS_PATH}N_50_2D_encoding/best_kp_ae_N_50_2D_lr_one_cycle_training.keras")
self._encoder = keras.models.load_model(f"{KPAE._MODELS_PATH}N_50_2D_encoding/best_kp_ae_N_50_2D_lr_one_cycle_training_encoder.keras")
self._decoder = keras.models.load_model(f"{KPAE._MODELS_PATH}N_50_2D_encoding/best_kp_ae_N_50_2D_lr_one_cycle_training_decoder.keras")

self._model = keras.models.load_model(
f"{KPAE._MODELS_PATH}N_50_2D_encoding/best_kp_ae_N_50_2D_lr_one_cycle_training.keras"
)
self._encoder = keras.models.load_model(
f"{KPAE._MODELS_PATH}N_50_2D_encoding/best_kp_ae_N_50_2D_lr_one_cycle_training_encoder.keras"
)
self._decoder = keras.models.load_model(
f"{KPAE._MODELS_PATH}N_50_2D_encoding/best_kp_ae_N_50_2D_lr_one_cycle_training_decoder.keras"
)
with open(f"{KPAE._MODELS_PATH}kp_scaler_N_50.pkl", "rb") as f:
self._scaler = pickle.load(f)
self._scaler = pickle.load(f)
3 changes: 2 additions & 1 deletion digneapy/transformers/keras_nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(
activations: Sequence[Optional[str]],
scale: bool = True,
):
"""Neural Network used to transform a space into another. This class uses a Tensorflow and Keras backend.
"""Neural Network used to transform a space into another. This class uses a Keras backend.
Args:
name (str): Name of the model to be saved with. Expected a .keras extension.
Expand All @@ -48,6 +48,7 @@ def __init__(
name = name + ".keras"

super().__init__(name)

self.input_shape = input_shape
self._shape = shape
self._activations = activations
Expand Down
20 changes: 5 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,13 @@ ext-modules = [

] },
]
[tool.setuptools.dynamic]
dependencies = { file = ["requirements.txt"] }

[project]
dependencies = [
"keras>=2.14.0",
"pandas==2.1.3",
"deap>=1.4",
"numpy==1.26.0",
"scikit-learn==1.5.0",
"scipy==1.11.4",
"tensorflow>=2.16",
"torch>=2.1.1",
"pybind11>=2.12.0",
"seaborn>=0.13.2",
"matplotlib>=3.7.1",
]
dynamic = ["dependencies"]
name = "digneapy"
dynamic = ["version"]
version = "0.2.3"
description = "Python version of the DIGNEA code for instance generation"
authors = [{ name = "Alejandro Marrero", email = "amarrerd@ull.edu.es" }]
readme = "README.md"
Expand Down Expand Up @@ -134,7 +124,7 @@ target-version = "py312"
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F", "I"]
select = ["E4", "E7", "E9", "F", "I", "NPY201"]
ignore = []

# Allow fix for all enabled rules (when `--fix`) is provided.
Expand Down
9 changes: 4 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
keras>=2.14.0
pandas==2.1.3
keras>=3.5.0
pandas>=2.2.2
deap>=1.4
numpy==1.26.0
numpy>=2.1.0
scikit-learn==1.5.0
scipy==1.11.4
tensorflow>=2.16
scipy==1.14.1
torch>=2.1.1
pybind11>=2.12.0
seaborn>=0.13.2
Expand Down
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ virtualenv>=20.26.2
build==1.2.1
cibuildwheel>=2.18.1
bump2version==0.5.11
ruff==0.4.8
ruff>=0.4.8
coverage==4.5.4
Sphinx>=5.0.0
sphinx-rtd-theme
Expand Down
15 changes: 15 additions & 0 deletions test_times.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python
# -*-coding:utf-8 -*-
"""
@File : test_times.py
@Time : 2024/09/11 13:58:58
@Author : Alejandro Marrero
@Version : 1.0
@Contact : amarrerd@ull.edu.es
@License : (C)Copyright 2024, Alejandro Marrero
@Desc : None
"""

import digneapy

print(f"Hello world: {digneapy.__version__}")

0 comments on commit 43cdafd

Please sign in to comment.