tensorflow / skflow

Simplified interface for TensorFlow (mimicking Scikit Learn) for Deep Learning
Apache License 2.0
3.18k stars 439 forks source link

Input 'Values' of HistogramSummary Op Type Mismatch #83

Closed terrytangyuan closed 8 years ago

terrytangyuan commented 8 years ago

Reproducible example: (master branch with update for dask stuff)

from skflow.io import *
import skflow
from sklearn import datasets
import random

random.seed(42)
iris = datasets.load_iris()
data = pd.DataFrame(iris.data)
data = dd.from_pandas(data, npartitions=2)
labels = pd.DataFrame(iris.target)
labels = dd.from_pandas(labels, npartitions=2)
classifier = skflow.TensorFlowLinearClassifier(n_classes=3)
classifier.fit(data, labels)

gives:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-8e0c6d4b2deb> in <module>()
     11 labels = dd.from_pandas(labels, npartitions=2)
     12 classifier = skflow.TensorFlowLinearClassifier(n_classes=3)
---> 13 classifier.fit(data, labels)

/Library/Python/2.7/site-packages/skflow-0.0.1-py2.7.egg/skflow/estimators/base.pyc in fit(self, X, y, logdir)
    185         if not self.continue_training or not self._initialized:
    186             # Sets up model and trainer.
--> 187             self._setup_training()
    188             # Initialize model parameters.
    189             self._trainer.initialize(self._session)

/Library/Python/2.7/site-packages/skflow-0.0.1-py2.7.egg/skflow/estimators/base.pyc in _setup_training(self)
    118             # Add histograms for X and y if they are floats.
    119             if self._data_feeder.input_dtype in (np.float32, np.float64):
--> 120                 tf.histogram_summary("X", self._inp)
    121             if self._data_feeder.output_dtype in (np.float32, np.float64):
    122                 tf.histogram_summary("y", self._out)

/Library/Python/2.7/site-packages/tensorflow/python/ops/summary_ops.pyc in histogram_summary(tag, values, collections, name)
     37   with ops.op_scope([tag, values], name, "HistogramSummary") as scope:
     38     val = gen_summary_ops._histogram_summary(
---> 39         tag=tag, values=values, name=scope)
     40     _Collect(val, collections, [ops.GraphKeys.SUMMARIES])
     41   return val

/Library/Python/2.7/site-packages/tensorflow/python/ops/gen_summary_ops.pyc in _histogram_summary(tag, values, name)
     32   """
     33   return _op_def_lib.apply_op("HistogramSummary", tag=tag, values=values,
---> 34                               name=name)
     35
     36

/Library/Python/2.7/site-packages/tensorflow/python/ops/op_def_library.pyc in apply_op(self, op_type_name, g, name, **keywords)
    403             if input_arg.type != types_pb2.DT_INVALID:
    404               raise TypeError("%s expected type of %s." %
--> 405                               (prefix, types_lib.as_dtype(input_arg.type).name))
    406             else:
    407               raise TypeError(

TypeError: Input 'values' of 'HistogramSummary' Op has type float64 that does not match expected type of float32.

Not sure exactly what happened but I tried to add more supported types in https://github.com/tensorflow/skflow/blob/master/skflow/estimators/base.py#L119 -- still getting this error.

Anything I missed?

terrytangyuan commented 8 years ago

So type of y is inferred to be int from dask.dataframes, could this cause the problem? I don't see anything wrong from API doc for tf.histogram_summary though. Any reason why the expected type needs to be float32? X is inferred to be float64 from dask.