Tried to convert 'shape' to a tensor and failed

I am new to greta. When I attempted to run the following example and got an error message. Do you know how to fix this issue? Thanks.

library(greta)

x <- as_data(iris$Petal.Length)
y <- as_data(iris$Sepal.Length)

int <- normal(0, 1)
coef <- normal(0, 3)
sd <- student(3, 0, 1, truncation = c(0, Inf))

mean <- int + coef * x

distribution(y) <- normal(mean, sd)

m <- model(int, coef, sd)

Error in py_call_impl(callable, dots$args, dots$keywords) :
ValueError: Tried to convert ‘shape’ to a tensor and failed. Error: Cannot convert a partially known TensorShape to a Tensor: (?, 1, 1)

1 Like

I’ve just got the same error. Mac OS 10.15.7, R version 4.1.1, greta 0.3.1. I installed greta et al. using the code here: https://www.causact.com/install-tensorflow-greta-and-causact.html#install-tensorflow-greta-and-causact

This is my full code and error message:

define a simple model

mu <- variable()
sigma <- normal(0, 3, truncation = c(0, Inf))
x <- rnorm(10)
distribution(x) <- normal(mu, sigma)

m <- model(mu, sigma)
Error in py_call_impl(callable, dots$args, dots$keywords) :
ValueError: Tried to convert ‘shape’ to a tensor and failed. Error: Cannot convert a partially known TensorShape to a Tensor: (?, 1, 1)

Detailed traceback:
File “/Users/robertoh/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/tensorflow/python/ops/gen_array_ops.py”, line 7715, in reshape
“Reshape”, tensor=tensor, shape=shape, name=name)
File “/Users/robertoh/Library/r-miniconda/envs/r-reticulate/lib/python3.7/site-packages/tensorflow/python/framework/op_def_library.py”, line 545, in _apply_op_helper
(input_name, err))

1 Like

Hi There!

Apologies for the late reply, just getting back from leave over the break.

Are you able to try this with the latest version on Greta on GitHub?

I am pretty sure this is related to an issue we had with a Tensorflow R package update.

You can install the latest version on Greta with

devtools::install_github("greta-dev/greta")

Let me know how you go?

Great, that works. Well, at least it’s warming up (both the mcmc and my laptop).

1 Like

Awesome! Great to hear it works. Thanks again for posting :slight_smile: