keras.layers.DenseFeatures(age_column)(x).numpy()报错
来源:5-3 feature_column使用
gong0037
2019-08-13
UnimplementedError Traceback (most recent call last)
in
3 age_column = feature_columns[7]
4 gender_column = feature_columns[0]
----> 5 print(keras.layers.DenseFeatures(age_column)(x))
6 print(keras.layers.DenseFeatures(gender_column)(x).numpy())
~/.virtualenvs/tf2_py3/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py in call(self, inputs, *args, **kwargs)
710 with base_layer_utils.autocast_context_manager(
711 input_list, self._mixed_precision_policy.should_cast_variables):
–> 712 outputs = self.call(inputs, *args, **kwargs)
713 self._handle_activity_regularization(inputs, outputs)
714 self._set_mask_metadata(inputs, outputs, input_masks)
~/.virtualenvs/tf2_py3/lib/python3.6/site-packages/tensorflow/python/feature_column/feature_column_v2.py in call(self, features, cols_to_output_tensors)
472 with ops.name_scope(column.name):
473 tensor = column.get_dense_tensor(transformation_cache,
–> 474 self._state_manager)
475 processed_tensors = self._process_dense_tensor(column, tensor)
476 if cols_to_output_tensors is not None:
~/.virtualenvs/tf2_py3/lib/python3.6/site-packages/tensorflow/python/feature_column/feature_column_v2.py in get_dense_tensor(self, transformation_cache, state_manager)
2797 # Feature has been already transformed. Return the intermediate
2798 # representation created by _transform_feature.
-> 2799 return transformation_cache.get(self, state_manager)
2800
2801 @deprecation.deprecated(_FEATURE_COLUMN_DEPRECATION_DATE,
~/.virtualenvs/tf2_py3/lib/python3.6/site-packages/tensorflow/python/feature_column/feature_column_v2.py in get(self, key, state_manager)
2560 column = key
2561 logging.debug(‘Transforming feature_column %s.’, column)
-> 2562 transformed = column.transform_feature(self, state_manager)
2563 if transformed is None:
2564 raise ValueError(‘Column {} is not supported.’.format(column.name))
~/.virtualenvs/tf2_py3/lib/python3.6/site-packages/tensorflow/python/feature_column/feature_column_v2.py in transform_feature(self, transformation_cache, state_manager)
2770 “”"
2771 input_tensor = transformation_cache.get(self.key, state_manager)
-> 2772 return self._transform_input_tensor(input_tensor)
2773
2774 @property
~/.virtualenvs/tf2_py3/lib/python3.6/site-packages/tensorflow/python/feature_column/feature_column_v2.py in _transform_input_tensor(self, input_tensor)
2745 if self.normalizer_fn is not None:
2746 input_tensor = self.normalizer_fn(input_tensor)
-> 2747 return math_ops.cast(input_tensor, dtypes.float32)
2748
2749 @deprecation.deprecated(_FEATURE_COLUMN_DEPRECATION_DATE,
~/.virtualenvs/tf2_py3/lib/python3.6/site-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
178 “”“Call target, and fall back on dispatchers if there is a TypeError.”""
179 try:
–> 180 return target(*args, **kwargs)
181 except (TypeError, ValueError):
182 # Note: convert_to_eager_tensor currently raises a ValueError, not a
~/.virtualenvs/tf2_py3/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py in cast(x, dtype, name)
687 x = ops.convert_to_tensor(x, name=“x”)
688 if x.dtype.base_dtype != base_type:
–> 689 x = gen_math_ops.cast(x, base_type, name=name)
690 if x.dtype.is_complex and base_type.is_floating:
691 logging.warn(“Casting complex to real discards imaginary part.”)
~/.virtualenvs/tf2_py3/lib/python3.6/site-packages/tensorflow/python/ops/gen_math_ops.py in cast(x, DstT, Truncate, name)
2174 else:
2175 message = e.message
-> 2176 _six.raise_from(_core._status_to_exception(e.code, message), None)
2177 # Add nodes to the TensorFlow graph.
2178 DstT = _execute.make_type(DstT, “DstT”)
~/.virtualenvs/tf2_py3/lib/python3.6/site-packages/six.py in raise_from(value, from_value)
UnimplementedError: Cast string to float is not supported [Op:Cast] name: dense_features_5/alone/Cast/
1回答
-
正十七
2019-08-14
同学你好,看问题错误的原因是字符串转int,
UnimplementedError: Cast string to float is not supported [Op:Cast] name: dense_features_5/alone/Cast/
猜测是不是你的某些列没有做转换就试图打印出来了?之前有没有这段代码?
for categorical_column in numeric_columns: feature_columns.append( tf.feature_column.numeric_column( categorical_column, dtype=tf.float32))
如果不成,可以用我们git上的代码试一下,看看跟你写的有什么区别。
00
相似问题