Skip to content

Commit

Permalink
remove TensorInput and SimplePolyNN
Browse files Browse the repository at this point in the history
  • Loading branch information
henrysky committed Jan 3, 2024
1 parent fba5e10 commit 8cec78f
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 70 deletions.
3 changes: 1 addition & 2 deletions astroNN/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
ApokascEncoderDecoder,
StarNet2017,
)
from astroNN.models.misc_models import Cifar10CNN, MNIST_BCNN, SimplePolyNN
from astroNN.models.misc_models import Cifar10CNN, MNIST_BCNN
from astroNN.nn.losses import losses_lookup
from astroNN.nn.utilities import Normalizer
from astroNN.shared.dict_tools import dict_list_to_dict_np, list_to_dict
Expand All @@ -37,7 +37,6 @@
"StarNet2017",
"Cifar10CNN",
"MNIST_BCNN",
"SimplePolyNN",
]

optimizers = keras.optimizers
Expand Down
2 changes: 0 additions & 2 deletions astroNN/models/apogee_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
MCDropout,
BoolMask,
StopGrad,
KLDivergenceLayer,
TensorInput,
VAESampling,
)
from astroNN.nn.losses import (
Expand Down
49 changes: 0 additions & 49 deletions docs/source/neuralnets/layers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -414,52 +414,3 @@ It can be used with keras or tensorflow.keras, you just have to import the funct
stopped_grad_layer = BoolMask(mask=....)(...)
# some layers ...
return model
TensorInput Layer
-----------------------

.. autoclass:: astroNN.nn.layers.TensorInput
:members: call, get_config


`TensorInput` takes tensorflow tensor as layer initialization and return the tensor.

`TensorInput` can be imported by

.. code-block:: python
:linenos:
from astroNN.nn.layers import TensorInput
For example, if you want to generate random tensor as other layers input and do not want it to register it as model input, you can

.. code-block:: python
:linenos:
from astroNN.nn.layers import TensorInput
# we use zeros loss just to demonstrate StopGrad works and no error backprop from StopGrad layer
from astroNN.nn.losses import zeros_loss
import numpy as np
from astroNN.shared.nn_tools import cpu_fallback
import tensorflow as tf
import keras
cpu_fallback() # force tf to use CPU
Input = keras.layers.Input
Dense = keras.layers.Dense
concatenate = keras.layers.concatenate
Model = keras.models.Model
# Data preparation
random_xdata = np.random.normal(0, 1, (100, 7514))
random_ydata = np.random.normal(0, 1, (100, 25))
input1 = Input(shape=[7514])
input2 = TensorInput(tensor=tf.random.normal(mean=0., stddev=1., shape=tf.shape(input1)))([])
output = Dense(25, name='dense')(concatenate([input1, input2]))
model = Model(inputs=input1, outputs=output)
model.compile(optimizer=keras.optimizers.SGD(lr=0.1),
loss='mse')
print(model.input_names)
>>> ['input_1'] # only input_1 as input_2 is not really an input we requiring user to input
17 changes: 0 additions & 17 deletions tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,22 +250,5 @@ def test_FastMCInference(self):
# make sure accelerated model has no variance (uncertainty) on deterministic model prediction
self.assertAlmostEqual(np.sum(sy[:, :, 1]), 0.0)

def test_TensorInput(self):
print("==========BoolMask tests==========")
from astroNN.nn.layers import TensorInput

input1 = Input(shape=[7514], name="input")
input2 = TensorInput(
tensor=keras.backend.random.normal(
mean=0.0, stddev=1.0, shape=keras.backend.shape(input1)
)
)([])
output = Dense(25, name="dense")(concatenate([input1, input2]))
model = Model(inputs=input1, outputs=output)
model.compile(optimizer="adam", loss="mse")

self.assertEqual(len(model.input_names), 1)


if __name__ == "__main__":
unittest.main()

0 comments on commit 8cec78f

Please sign in to comment.