Skip to content

Commit

Permalink
remove large keras import
Browse files Browse the repository at this point in the history
  • Loading branch information
malihass committed Apr 4, 2024
1 parent c1da97d commit 86f27a6
Show file tree
Hide file tree
Showing 18 changed files with 39 additions and 39 deletions.
4 changes: 3 additions & 1 deletion BayesianCalibration_spm/cal_nosigma.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import os
import sys

import keras
import numpy as np
import tensorflow as tf
import tf2jax
from keras import layers
from keras.backend import set_floatx

set_floatx("float64")

parser = argparse.ArgumentParser(description="BNN interface for pouch cells")
parser.add_argument(
Expand Down
4 changes: 2 additions & 2 deletions BayesianCalibration_spm/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
sys.path.append(args.utilFolder)

import argument
import keras
import tensorflow as tf
from keras import layers, regularizers
from myNN import *
from keras.backend import set_floatx

keras.backend.set_floatx("float64")
set_floatx("float64")

# Read command line arguments
args_spm = argument.initArg()
Expand Down
6 changes: 3 additions & 3 deletions pinn_spm_param/postProcess/computeError.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from pathlib import Path

import argument
import keras
import tensorflow as tf
from keras import layers, regularizers
from myNN import *
from tensorflow import keras
from keras.backend import set_floatx

set_floatx("float64")

keras.backend.set_floatx("float64")
from forwardPass import (
from_param_list_to_str,
make_data_dict,
Expand Down
4 changes: 2 additions & 2 deletions pinn_spm_param/postProcess/plotCorrelationPINNvsData.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

sys.path.append("../util")
import argument
import keras
import tensorflow as tf
from keras import layers, regularizers
from myNN import *
from plotsUtil_batt import *
from keras.backend import set_floatx

keras.backend.set_floatx("float64")
set_floatx("float64")

from init_pinn import initialize_nn_from_params_config, safe_load

Expand Down
4 changes: 2 additions & 2 deletions pinn_spm_param/postProcess/plotData.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

sys.path.append("../util")
import argument
import keras
import tensorflow as tf
from keras import layers, regularizers
from myNN import *
from plotsUtil_batt import *
from keras.backend import set_floatx

keras.backend.set_floatx("float64")
set_floatx("float64")

print("\n\nINFO: PLOTTING DATA OBTAINED FROM FINITE DIFFERENCE\n\n")

Expand Down
4 changes: 2 additions & 2 deletions pinn_spm_param/postProcess/plotPINNResult.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

sys.path.append("../util")
import argument
import keras
import tensorflow as tf
from forwardPass import (
from_param_list_to_str,
Expand All @@ -17,8 +16,9 @@
from keras import layers, regularizers
from myNN import *
from plotsUtil_batt import *
from keras.backend import set_floatx

keras.backend.set_floatx("float64")
set_floatx("float64")

print("\n\nINFO: PLOTTING RESULTS OF THE PINN TRAINING\n\n")

Expand Down
4 changes: 2 additions & 2 deletions pinn_spm_param/postProcess/plotPINNResult_movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from pathlib import Path

import argument
import keras
import tensorflow as tf
from keras import layers, regularizers
from myNN import *
from plotsUtil_batt import *
from keras.backend import set_floatx

keras.backend.set_floatx("float64")
set_floatx("float64")

from forwardPass import (
from_param_list_to_str,
Expand Down
4 changes: 2 additions & 2 deletions pinn_spm_param/util/_losses.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import argument
import keras
import numpy as np
import tensorflow as tf
from conditionalDecorator import conditional_decorator
from keras.backend import set_floatx

keras.backend.set_floatx("float64")
set_floatx("float64")

# Read command line arguments
args = argument.initArg()
Expand Down
4 changes: 2 additions & 2 deletions pinn_spm_param/util/_rescale.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import argument
import keras
import numpy as np
import tensorflow as tf
from conditionalDecorator import conditional_decorator
from keras.backend import set_floatx

keras.backend.set_floatx("float64")
set_floatx("float64")

# Read command line arguments
args = argument.initArg()
Expand Down
7 changes: 3 additions & 4 deletions pinn_spm_param/util/custom_activations.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import argument
import keras
import numpy as np
import tensorflow as tf
from conditionalDecorator import conditional_decorator
from keras import backend as K
from keras.layers import Activation
from keras.utils import get_custom_objects
from keras.backend import set_floatx

keras.backend.set_floatx("float64")
set_floatx("float64")

# Read command line arguments
args = argument.initArg()
Expand All @@ -24,7 +23,7 @@ def swish_activation(x):
Swish activation - with beta not-traininable!
"""
return x * K.sigmoid(x)
return x * tf.math.sigmoid(x)


class Bswish(keras.layers.Layer):
Expand Down
4 changes: 2 additions & 2 deletions pinn_spm_param/util/forwardPass.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

sys.path.append("../util")
import argument
import keras
import tensorflow as tf
from keras import layers, regularizers
from myNN import *
from keras.backend import set_floatx

keras.backend.set_floatx("float64")
set_floatx("float64")

from init_pinn import initialize_nn_from_params_config

Expand Down
1 change: 0 additions & 1 deletion pinn_spm_param/util/init_pinn.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,6 @@ def initialize_nn(args, input_params):
)

if not args.optimized:
import keras
from keras.utils import plot_model

try:
Expand Down
4 changes: 2 additions & 2 deletions pinn_spm_param/util/myNN.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import time

import argument
import keras
import numpy as np
import tensorflow as tf
from _losses import (
Expand All @@ -25,8 +24,9 @@
from keras.layers import *
from keras.models import Model
from prettyPlot.progressBar import print_progress_bar
from keras.backend import set_floatx

keras.backend.set_floatx("float64")
set_floatx("float64")

# Read command line arguments
args = argument.initArg()
Expand Down
4 changes: 2 additions & 2 deletions pinn_spm_param/util/spm.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import sys

import keras
import numpy as np
import tensorflow as tf
from thermo import *
from keras.backend import set_floatx

keras.backend.set_floatx("float64")
set_floatx("float64")

print("INFO: USING REALISTIC SPM MODEL")

Expand Down
4 changes: 2 additions & 2 deletions pinn_spm_param/util/spm_simpler.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
import sys

import keras
import numpy as np
import tensorflow as tf
from thermo import *
from keras.backend import set_floatx

keras.backend.set_floatx("float64")
set_floatx("float64")

print("INFO: USING SIMPLE SPM MODEL")

Expand Down
8 changes: 4 additions & 4 deletions pinn_spm_param/util/tf_lineInterp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def generateTFSpline(x, y, filename, funcname, precision="float64", mode="w+"):
if mode == "w+":
f.write("import argument\n")
f.write("import numpy as np\n")
f.write("import keras\n")
f.write("import tensorflow as tf\n")
f.write("from conditionalDecorator import conditional_decorator\n")
f.write("from keras.backend import set_floatx\n")
f.write("\n")
f.write(f'keras.backend.set_floatx("{precision}")\n')
f.write(f'set_floatx("{precision}")\n')
f.write("\n")
f.write("# Read command line arguments\n")
f.write("args = argument.initArg()\n")
Expand Down Expand Up @@ -68,11 +68,11 @@ def generateTFPoly(coeffs, filename, funcname, precision="float64", mode="w+"):
if mode == "w+":
f.write("import argument\n")
f.write("import numpy as np\n")
f.write("import keras\n")
f.write("import tensorflow as tf\n")
f.write("from conditionalDecorator import conditional_decorator\n")
f.write("from keras.backend import set_floatx\n")
f.write("\n")
f.write(f'keras.backend.set_floatx("{precision}")\n')
f.write(f'set_floatx("{precision}")\n')
f.write("\n")
f.write("# Read command line arguments\n")
f.write("args = argument.initArg()\n")
Expand Down
4 changes: 2 additions & 2 deletions pinn_spm_param/util/thermo.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import sys

import keras
import numpy as np
import tensorflow as tf
from uocp_cs import uocp_a_fun_x, uocp_c_fun_x
from keras.backend import set_floatx

keras.backend.set_floatx("float64")
set_floatx("float64")


def uocp_a_simp(cs_a, csanmax):
Expand Down
4 changes: 2 additions & 2 deletions pinn_spm_param/util/uocp_cs.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import argument
import keras
import numpy as np
import tensorflow as tf
from conditionalDecorator import conditional_decorator
from keras.backend import set_floatx

keras.backend.set_floatx("float64")
set_floatx("float64")

# Read command line arguments
args = argument.initArg()
Expand Down

0 comments on commit 86f27a6

Please sign in to comment.