Short Version:
I have a custom model with a layer which can be parameterized by a value sigma
.
I am using this model with Tensorflow Estimator:
classifier = tf.estimator.Estimator(model_fn=model_fun)
And for instance the training is declared as follows:
# Train the model
train_input_fn=tf.estimator.inputs.numpy_input_fn(x={"x": train_data},
batch_size=batch_size, num_epochs=nEpochs, shuffle=True)
classifier.train(input_fn=train_input_fn,max_steps=nSteps)
In this setup, how can I pass sigma
to my custom Estimator so that it can be trained / evaluated with different values?
Longer Version:
I am working on this DNN Autoencoder, for which I have a layer that adds Gaussian noise by considering random_normal() values from a distribution of known standard deviation sigma.
This is a model of a communication system, and the output logits (from the final layer) is retrieved using the model.predict() function, and my metric namely Bit Error rate is computed by a custom function in Tensor Flow 1.5, Python 3.5, Windows 10.
The problem is as follows:
I want to train the system for sigma=sigma1, and retrieve the output logits.(This part is fine, and I am able to get the desired output.)
I also want to predict the outputs for sigma=sigma2, sigma=sigma3, sigma=sigma4 and so on using the same Estimator that was defined(IN THE SAME PROGRAM).
My DNN looks like this and is defined in the model function:
Input Layer- One Hot Encoded Values are fed here.
Dense+ReLU
Dense+Linear
Normalization Layer
Addition of Noise: Here I add a tf.random_normal(stddev=sigma) to the output of the previous layer. This is where I would appreciate assistance in understanding how I can use different sigmas for each run(train/test). I suppose you could say sigma ought to be a parameter that can have different values for each test run.
gnoise=tf.random_normal(mean=0,stddev=sigma) Then the layer's output=norm(which is the prev layer's output)+gnoise
Dense+RELU
Softmax-Output is Logits
I define my estimator as:
classifier = tf.estimator.Estimator(model_fn=model_fun)
And the training is declared as follows:
# Train the model
train_input_fn=tf.estimator.inputs.numpy_input_fn(x={"x": train_data},
batch_size=batch_size, num_epochs=nEpochs, shuffle=True)
classifier.train(input_fn=train_input_fn,max_steps=nSteps)
The predict function is declared and called as:
pred_input_fn=tf.estimator.inputs.numpy_input_fn(x={"x": test_data},
batch_size=batch_size, num_epochs=nEpochs, shuffle=False)
pred_results = classifier.predict(input_fn=pred_input_fn)