TypeError:传递给参数'ref'的值的DataType int64不在允许值列表中:float32,int32,qint8,quint8,qint32

时间:2018-01-06 13:14:39

标签: python tensorflow raspberry-pi

我在使用Raspberry Pi 3并在安装带有https://github.com/samjabrahams/tensorflow-on-raspberry-pi/blob/master/GUIDE.md#3-build-bazel指示的Tensorflow之后,我正在尝试使用Python运行脚本。

  

Python版本:Python 2.7.9

     

tensorflow._ 版本 _:'1.5.0-rc0'

我的代码:

# FEATURES, LABEL and COLUMNS are defined 

def get_input_fn(data_set, num_epochs=None, shuffle=True):
      return tf.estimator.inputs.pandas_input_fn(
  x=pd.DataFrame({k: data_set[k].values for k in FEATURES}),
  y = pd.Series(data_set[LABEL].values),
  num_epochs=num_epochs,
  shuffle=shuffle)

# ...

data_train_np = np.zeros((data_train_size,7),dtype=np.float)
# Creation of data_train_np values ...
data_train=pd.DataFrame(data_train_np,columns=COLUMNS)

# ...

feature_cols = [tf.feature_column.numeric_column(k) for k in FEATURES] 
regressor = tf.estimator.DNNRegressor(feature_columns=feature_cols,hidden_units=[256,64,32])
regressor.train(input_fn=get_input_fn(data_train), steps=100)

运行脚本后,我有:

INFO:tensorflow:Using default config.
INFO:tensorflow:Using config: {'_save_checkpoints_secs': 600, '_session_config': None, '_keep_checkpoint_max': 5, '_task_type': 'worker', '_is_chief': True, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x67d76650>, '_evaluation_master': '', '_save_checkpoints_steps': None, '_keep_checkpoint_every_n_hours': 10000, '_service': None, '_num_ps_replicas': 0, '_tf_random_seed': None, '_master': '', '_num_worker_replicas': 1, '_task_id': 0, '_log_step_count_steps': 100, '_model_dir': './checkpoint/data_model_location_256-64-32', '_save_summary_steps': 100}

Traceback (most recent call last):
  File "UberWeatherLocation.py", line 135, in <module>
    regressor.train(input_fn=get_input_fn(data_train), steps=10)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/estimator.py", line 314, in train
    loss = self._train_model(input_fn, hooks, saving_listeners)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/estimator.py", line 744, in _train_model
    features, labels, model_fn_lib.ModeKeys.TRAIN, self.config)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/estimator.py", line 726, in _call_model_fn
    model_fn_results = self._model_fn(features=features, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/canned/dnn.py", line 448, in _model_fn
    config=config)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/canned/dnn.py", line 189, in _dnn_model_fn
    logits=logits)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/canned/head.py", line 1113, in create_estimator_spec
    train_op=train_op_fn(weighted_sum_loss))
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/canned/dnn.py", line 182, in _train_op_fn
    global_step=training_util.get_global_step())
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/optimizer.py", line 365, in minimize
    name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/optimizer.py", line 534, in apply_gradients
    apply_updates = state_ops.assign_add(global_step, 1, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/state_ops.py", line 244, in assign_add
    ref, value, use_locking=use_locking, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_state_ops.py", line 101, in assign_add
    "AssignAdd", ref=ref, value=value, use_locking=use_locking, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 609, in _apply_op_helper
    param_name=input_name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 60, in _SatisfiesTypeConstraint
    ", ".join(dtypes.as_dtype(x).name for x in allowed_list)))
TypeError: Value passed to parameter 'ref' has DataType int64 not in list of allowed values: float32, int32, qint8, quint8, qint32

我看到了一些类似错误消息的问题,但我的情况不知道如何修复它。

感谢您的回答!

1 个答案:

答案 0 :(得分:0)

您是否看过现有的官方Raspberry Pi图片?

https://petewarden.com/2017/08/20/cross-compiling-tensorflow-for-the-raspberry-pi/

这避免了Bazel on-device编译步骤。