tensorflow / tensorflow/probability

AttributeError: 'UserRegisteredTypeKerasTensor' object has no attribute 'mean' error raised.

Open
#1,484 10 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.