Skip to content

Commit

Permalink
remove TensorInput
Browse files Browse the repository at this point in the history
  • Loading branch information
henrysky committed Jan 3, 2024
1 parent fba5e10 commit c483099
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 68 deletions.
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 c483099

Please sign in to comment.