You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My conda list | grep keras versions are:
keras 2.15.0
keras-preprocessing 1.1.2
importnumpyasnpfromtensorflow.keras.layersimportInput, Denseimporttensorflow_probabilityastfpfromtensorflow.keras.modelsimportModelfromtensorflow.keras.optimizersimportAdamimporttensorflowastfinputDim=10targetDim=1#build train datasamples=1000input_list= []
foriiinrange(samples):
input_list.append(np.arange(inputDim))
input_arr=np.array(input_list)
target=arr=np.random.normal(5.0, 0.5, (samples,1))
#define modelinput=Input(shape=(inputDim))
distribution_params=Dense(2)(input)
outputs=tfp.layers.IndependentNormal(targetDim)(distribution_params)
#define lossdefnll(targets, estimated_distribution):
return-estimated_distribution.log_prob(targets)
#compile and fit modeloptimizer=Adam()
model=Model(inputs= [input] , outputs=[outputs])
model.compile(optimizer=optimizer, loss=nll)#, metrics = lossFunction)model.summary()
model.fit(input_arr,target, shuffle=True, epochs=500)#, verbose = 2)# test predictionprediction=model(np.expand_dims(np.arange(inputDim), axis=0))
print("prediction mean : ", prediction.mean())
print("stdDev = ", prediction.stddev())
#export training signature@tf.functiondeftrainOp(inputs, targets):
### has to return loss ###withtf.GradientTape() astape:
predictions=model(inputs)
loss=nll(predictions, targets)
gradients=tape.gradient(loss, model.trainable_variables)
optimizer.apply_gradients(zip(gradients, model.trainable_variables))
returnlosssignatures= {}
signatures["trainOp"] =trainOp.get_concrete_function(inputs=tf.TensorSpec((None, inputDim), tf.float32),
targets=tf.TensorSpec((None, targetDim), tf.float32))
model.save('./testExport/', save_traces=False, signatures=signatures)
failes with : AttributeError: in user code:
File "/home/aberberich/Shared/Andi/tf2Api/reworked/min_export_failure.py", line 57, in trainOp *
loss = nll(predictions, targets)
File "/home/aberberich/Shared/Andi/tf2Api/reworked/min_export_failure.py", line 37, in nll *
return -estimated_distribution.log_prob(targets)
AttributeError: 'SymbolicTensor' object has no attribute 'log_prob'`
The text was updated successfully, but these errors were encountered:
AndiBerber
changed the title
Training signature export failes due to distribution->tensor conversion
AttributeError: 'SymbolicTensor' object has no attribute 'log_prob' when exporting train signature with IndependentNormal` layer
Feb 21, 2024
AndiBerber
changed the title
AttributeError: 'SymbolicTensor' object has no attribute 'log_prob' when exporting train signature with IndependentNormal` layer
AttributeError: 'SymbolicTensor' object has no attribute 'log_prob' when exporting train signature with IndependentNormal layer
Feb 21, 2024
I want to export the training signature to train my model with the C++ API. However, I am not able to export the model, even after reading through
https://github.com/tensorflow/probability/issues/742 ,
https://github.com/tensorflow/tensorflow/issues/36181
https://stackoverflow.com/questions/59743872/when-training-a-variational-bayesian-neural-network-in-tfp-how-can-i-visualize
My
conda list | grep tensorflow
versions are:tensorflow 2.15.0.post1
tensorflow-estimator 2.15.0
tensorflow-io-gcs-filesystem 0.36.0
tensorflow-probability 0.23.0
My
conda list | grep keras
versions are:keras 2.15.0
keras-preprocessing 1.1.2
failes with :
AttributeError: in user code
:The text was updated successfully, but these errors were encountered: