TypeError: Failed to convert object of type <class ‘tensorflow.python.framework.sparse_tensor.SparseTensor’> to Tensor. Contents: SparseTensor(indices=Tensor(“F_traffic_volume/Placeholder:0”, shape=(None, 2), dtype=int64), values=Tensor(“Cast:0”, shape=(None,), dtype=float32), dense_shape=Tensor(“F_traffic_volume/Placeholder_2:0”, shape=(2,), dtype=int64)). Consider casting elements to a supported type.
That is what I code:
# Keep as is. No tft function needed.
for key in _CATEGORICAL_FEATURE_KEYS:
outputs[_transformed_name(key)] = None
# Use `tf.cast` to cast the label key to float32 and fill in the missing values.
traffic_volume = tf.cast(inputs[_VOLUME_KEY], tf.float32)
# Create a feature that shows if the traffic volume is greater than the mean and cast to an int
outputs[_transformed_name(_VOLUME_KEY)] = tf.cast(
# Use `tf.greater` to check if the traffic volume in a row is greater than the mean of the entire traffic volumn column
tf.greater(traffic_volume, tft.mean(traffic_volume)), tf.int64)
Hi! You’re on the right track. To resolve this, let’s go back a bit to the blank exercise. The last three lines of the boilerplate should look like:
outputs[_transformed_name(_VOLUME_KEY)] = tf.cast(
# Use `tf.greater` to check if the traffic volume in a row is greater than the mean of the entire traffic volumn column
tf.greater(None, None(tf.cast(inputs[_VOLUME_KEY], tf.float32))),
tf.int64)
You should only modify the second line and only the None placeholders. inputs[_VOLUME_KEY] should be cast into a float. Then the result of tf.greater will be cast into tf.int64. Hope this helps!
I am stuck at exactly the same place. Can you point me to something that documents how to get the mean? I can’t see anywhere that a specific statistics item (mean, min, max, …) is accessed. I see tft.scale_to_z_score which uses the mean. I can also read the mean for traffic volume from the output in section 2.2. Any pointers would be appreciated.
thanks