0

Hi I am trying to implement GMM using tensorflow. But I am getting the following error :- ValueError: Features are incompatible with given information. Given features: Tensor("input:0", shape=(?, 198), dtype=float32), required signatures: TensorSignature(dtype=tf.float64, shape=TensorShape([Dimension(None), Dimension(198)]), is_sparse=False).

Following is my code:-

from tensorflow.contrib.factorization.python.ops import gmm as gmm_lib
import numpy as np
num_clusters = 200
x = np.array([[random.random() for i in range(198)] for j in range(2384)])
gmm = gmm_lib.GMM(num_clusters, batch_size=1)
gmm.fit(x.astype('float32'),steps=300)
yy = gmm.predict(x,y=None)

x is a numpy array of shape (2384, 198)

Stack Trace:-

    Traceback (most recent call last):
  File "C:\Users\#####\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-36-2078a841d9ee>", line 1, in <module>
    gmm.fit(x.astype('float32'),steps=300)
  File "C:\Users\#####\Anaconda3\lib\site-packages\tensorflow\contrib\factorization\python\ops\gmm.py", line 133, in fit
    init_feed_fn=self._data_feeder.get_feed_dict_fn())
  File "C:\Users\#####\Anaconda3\lib\site-packages\tensorflow\contrib\factorization\python\ops\gmm.py", line 266, in _legacy_train_model
    estimator._check_inputs(features, labels)  # pylint: disable=protected-access
  File "C:\Users\#####\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\estimators\estimator.py", line 731, in _check_inputs
    (str(features), str(self._features_info)))
ValueError: Features are incompatible with given information. Given features: Tensor("input:0", shape=(?, 198), dtype=float32), required signatures: TensorSignature(dtype=tf.float64, shape=TensorShape([Dimension(None), Dimension(198)]), is_sparse=False).

Update:-

from tensorflow.contrib.factorization.python.ops import gmm as gmm_lib
gmm = gmm_lib.GMM(num_clusters, batch_size=1)
gmm.fit(x.astype('float64'),steps=300)
yy = gmm.predict(x,y=None)

If pass a float64 data then I get the following error:-

    WARNING:tensorflow:float64 is not supported by many models, consider casting to float32.
Traceback (most recent call last):
File "C:\Users\gidnri6\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2881, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-7-13c656388647>", line 1, in <module>
clusters_gmm = cluster_data(processed_data.values, num_clusters)
File "<ipython-input-6-c0e495bfbd0d>", line 4, in cluster_data
gmm.fit(x,steps=300)
File "C:\Users\gidnri6\Anaconda3\lib\site-packages\tensorflow\contrib\factorization\python\ops\gmm.py", line 133, in fit
init_feed_fn=self._data_feeder.get_feed_dict_fn())
File "C:\Users\gidnri6\Anaconda3\lib\site-packages\tensorflow\contrib\factorization\python\ops\gmm.py", line 274, in _legacy_train_model
train_ops = estimator._get_train_ops(features, labels)  # pylint: disable=protected-access
File "C:\Users\gidnri6\Anaconda3\lib\site-packages\tensorflow\contrib\factorization\python\ops\gmm.py", line 201, in _get_train_ops
self._params)
File "C:\Users\gidnri6\Anaconda3\lib\site-packages\tensorflow\contrib\factorization\python\ops\gmm_ops.py", line 496, in gmm
covariance_type, random_seed)
File "C:\Users\gidnri6\Anaconda3\lib\site-packages\tensorflow\contrib\factorization\python\ops\gmm_ops.py", line 146, in __init__
self._create_variables(data, initial_means)
File "C:\Users\gidnri6\Anaconda3\lib\site-packages\tensorflow\contrib\factorization\python\ops\gmm_ops.py", line 179, in _create_variables
cov = _covariance(first_shard, False) + self._min_var
File "C:\Users\gidnri6\Anaconda3\lib\site-packages\tensorflow\contrib\factorization\python\ops\gmm_ops.py", line 63, in _covariance
cov = math_ops.matmul(x, x, transpose_a=True) / (num_points - 1)
File "C:\Users\gidnri6\Anaconda3\lib\site-packages\tensorflow\python\ops\math_ops.py", line 883, in binary_op_wrapper
y = ops.convert_to_tensor(y, dtype=x.dtype.base_dtype, name="y")
File "C:\Users\gidnri6\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 651, in convert_to_tensor
as_ref=False)
File "C:\Users\gidnri6\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 716, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "C:\Users\gidnri6\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 589, in _TensorTensorConversionFunction
% (dtype.name, t.dtype.name, str(t)))
ValueError: Tensor conversion requested dtype float64 for Tensor with dtype float32: 'Tensor("sub_1:0", shape=(), dtype=float32)'
Rahul
  • 645
  • 1
  • 9
  • 21
  • The error message says that it's expecting a double (`float64`) and you're giving it a single-precision float (`float32`). It's likely that if you put `float64` in the code above, it would work. – drpng Feb 17 '17 at 19:57
  • @drpng I tried to do that but I got a new error :- ValueError: Tensor conversion requested dtype float64 for Tensor with dtype float32: 'Tensor("sub_1:0", shape=(), dtype=float32)' – Rahul Feb 20 '17 at 05:39
  • What is num_clusters? What is x? Your example is underspecified. – Paul Tucker Feb 23 '17 at 00:22
  • @Paul Tucker `num_clusters=200` and x is numpy bd array of shape (2384,198). the individual values of x are between 0 and 1 – Rahul Feb 23 '17 at 00:35
  • @PaulTucker I have updated the code. Please look into it – Rahul Feb 23 '17 at 00:54
  • I tried this program fragment: (ugh: can't post code here). Basically, your program doesn't work. x.astype() returns an error: list object has no attribute 'astype'. – Paul Tucker Feb 23 '17 at 01:11
  • @PaulTucker Sorry It was my mistake. `x = np.array([[random.random() for i in range(198)] for j in range(2384)])`. Please try now. – Rahul Feb 23 '17 at 01:27
  • @PaulTucker. If possible please try to implement skflow gmm_test from [here](https://github.com/tensorflow/tensorflow/blob/32bd3d024f33e920a67a1081bc0ae0048350fdee/tensorflow/contrib/factorization/python/ops/gmm_test.py) – Rahul Feb 23 '17 at 01:30
  • Now I'm getting a different error: InvalidArgumentError (see above for traceback): assertion failed: [] [Condition x <= y did not hold element-wise: x = ] [assert_less_equal/x:0] [200] [y = ] [strided_slice_1:0] [1] Does this really work for random x? Please update your program so that it produces the error you cite, on a vanilla TF 1.0 install. – Paul Tucker Feb 23 '17 at 01:44
  • @PaulTucker `from tensorflow.contrib.factorization.python.ops import gmm as gmm_lib import random import numpy as np x = np.array([[random.random() for i in range(198)] for j in range(2384)]) gmm = gmm_lib.GMM(200,random_seed=0) gmm.fit(x,steps=0)` – Rahul Feb 23 '17 at 02:04
  • @PaulTucker The error will vary depending on the type of x in the line `gmm.fit(x,steps=0)` – Rahul Feb 23 '17 at 02:06
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/136416/discussion-between-rahul-and-paul-tucker). – Rahul Feb 23 '17 at 05:24

0 Answers0