tensorflow / tensorflow/probability
AttributeError: 'UserRegisteredTypeKerasTensor' object has no attribute 'mean' error raised.
Open
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 4.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
Please can anyone let me know why the following code:
from tensorflow.keras.layers import Input
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import Concatenate
from tensorflow.keras.models import Model
from tensorflow.keras.optimizers import Adam
def neg_log_likelihood(y, distr):
return -distr.log_prob(y)
def my_dist(params): #723
return tfd.Normal(loc=params, scale=1)
inputs = Input(shape=(1,))
params = Dense(1)(inputs)
dist = tfp.layers.DistributionLambda(my_dist)(params)
model_sd1 = Model(inputs=inputs, outputs=dist)
model_sd1.compile(Adam(), loss=neg_log_likelihood)
And then running the following code;
model_mean_sd1 = Model(inputs=inputs, outputs=dist.mean())
leads to the following error:
AttributeError: 'UserRegisteredTypeKerasTensor' object has no attribute 'mean'
Any help will be greatly appreciated. Thanks.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied Python example and inspect the interaction between tensorflow.keras Model, tfp.layers.DistributionLambda, and the dist.mean() output expression. No repository file or test is named; done would mean determining the cause of the reported AttributeError and documenting or implementing a verified resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100