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)'