Skip to content

Commit

Permalink
additional test and added gaussian kernel init to keras custom objects
Browse files Browse the repository at this point in the history
  • Loading branch information
grantbuster committed May 7, 2024
1 parent c32187c commit c6d9b24
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions phygnn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
from .base import CustomNetwork, GradientUtils
from .phygnn import PhysicsGuidedNeuralNetwork
from .layers import Layers, HiddenLayers
from .layers.custom_layers import GaussianKernelInit2D
from .utilities import PreProcess, tf_isin, tf_log10
from phygnn.version import __version__
from tensorflow.keras.utils import get_custom_objects

get_custom_objects()['GaussianKernelInit2D'] = GaussianKernelInit2D

__author__ = """Grant Buster"""
__email__ = "[email protected]"
Expand Down
7 changes: 6 additions & 1 deletion tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,8 @@ def test_gaussian_kernel():
assert kernels[1].min() > kernels[0].min()

layers = [{'class': 'Conv2D', 'filters': 16, 'kernel_size': 3,
'kernel_initializer': GaussianKernelInit2D()}]
'kernel_initializer': GaussianKernelInit2D(),
'trainable': False}]
model1 = TfModel.build(['a'], ['b'], hidden_layers=layers,
input_layer=False, output_layer=False)
x_in = np.random.uniform(0, 1, (10, 12, 12, 1))
Expand All @@ -493,3 +494,7 @@ def test_gaussian_kernel():
out2 = model2.predict(x_in)
assert np.allclose(kernel1, kernel2)
assert np.allclose(out1, out2)

layer = model2.layers[0]
x_in = np.random.uniform(0, 1, (10, 24, 24, 1))
out3 = model2.predict(x_in)

0 comments on commit c6d9b24

Please sign in to comment.