- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是机器学习新手,我正在尝试按照本教程来掌握:
https://www.tensorflow.org/tutorials/estimator/boosted_trees
from __future__ import absolute_import, division, print_function, unicode_literals
import numpy as np
import pandas as pd
from IPython.display import clear_output
from matplotlib import pyplot as plt
# Load dataset.
dftrain = pd.read_csv('https://storage.googleapis.com/tf-datasets/titanic/train.csv')
dfeval = pd.read_csv('https://storage.googleapis.com/tf-datasets/titanic/eval.csv')
y_train = dftrain.pop('survived')
y_eval = dfeval.pop('survived')
import tensorflow as tf
tf.random.set_seed(123)
fc = tf.feature_column
CATEGORICAL_COLUMNS = ['sex', 'n_siblings_spouses', 'parch', 'class', 'deck',
'embark_town', 'alone']
NUMERIC_COLUMNS = ['age', 'fare']
def one_hot_cat_column(feature_name, vocab):
return tf.feature_column.indicator_column(
tf.feature_column.categorical_column_with_vocabulary_list(feature_name,
vocab))
feature_columns = []
for feature_name in CATEGORICAL_COLUMNS:
# Need to one-hot encode categorical features.
vocabulary = dftrain[feature_name].unique()
feature_columns.append(one_hot_cat_column(feature_name, vocabulary))
for feature_name in NUMERIC_COLUMNS:
feature_columns.append(tf.feature_column.numeric_column(feature_name,
dtype=tf.float32))
# Use entire batch since this is such a small dataset.
NUM_EXAMPLES = len(y_train)
def make_input_fn(X, y, n_epochs=None, shuffle=True):
def input_fn():
dataset = tf.data.Dataset.from_tensor_slices((dict(X), y))
if shuffle:
dataset = dataset.shuffle(NUM_EXAMPLES)
# For training, cycle thru dataset as many times as need (n_epochs=None).
dataset = dataset.repeat(n_epochs)
# In memory training doesn't use batching.
dataset = dataset.batch(NUM_EXAMPLES)
return dataset
return input_fn
# Training and evaluation input functions.
train_input_fn = make_input_fn(dftrain, y_train)
eval_input_fn = make_input_fn(dfeval, y_eval, shuffle=False, n_epochs=1)
linear_est = tf.estimator.LinearClassifier(feature_columns)
# Train model.
linear_est.train(train_input_fn, max_steps=100)
我删除了大部分不必要的代码,使其更加简洁。
一切正常,直到我调用 Linear_est.train(train_input_fn, max_steps=100) 函数。之后我收到以下错误消息。请原谅我有一大堆错误代码,因为我不知道哪一部分是重要的。
2020-01-03 19:10:31.309875: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
WARNING:tensorflow:Using temporary folder as model directory: C:\Users\bueny\AppData\Local\Temp\tmpqudxt4e5
WARNING:tensorflow:From C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\ops\resource_variable_ops.py:1630: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
WARNING:tensorflow:From C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\training\training_util.py:236: Variable.initialized_value (from tensorflow.python.ops.variables) is deprecated and will be removed in a future version.
Instructions for updating:
Use Variable.read_value. Variables in 2.X are initialized automatically both in eager and graph (inside tf.defun) contexts.
2020-01-03 19:10:33.796478: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-01-03 19:10:34.518560: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: GeForce MX150 major: 6 minor: 1 memoryClockRate(GHz): 1.0375
pciBusID: 0000:02:00.0
2020-01-03 19:10:34.518746: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2020-01-03 19:10:34.519194: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
WARNING:tensorflow:Layer linear/linear_model is casting an input tensor from dtype float64 to the layer's dtype of float32, which is new behavior in TensorFlow 2. The layer has dtype float32 because it's dtype defaults to floatx.
If you intended to run this layer in float32, you can safely ignore this warning. If in doubt, this warning is likely only an issue if you are porting a TensorFlow 1.X model to TensorFlow 2.
To change all layers to have dtype float64 by default, call `tf.keras.backend.set_floatx('float64')`. To change just this layer, pass dtype='float64' to the layer constructor. If you are the author of this layer, you can disable autocasting by passing autocast=False to the base Layer constructor.
WARNING:tensorflow:From C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\feature_column\feature_column_v2.py:518: Layer.add_variable (from tensorflow.python.keras.engine.base_layer) is deprecated and will be removed in a future version.
Instructions for updating:
Please use `layer.add_weight` method instead.
WARNING:tensorflow:From C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\feature_column\feature_column_v2.py:4276: IndicatorColumn._variable_shape (from tensorflow.python.feature_column.feature_column_v2) is deprecated and will be removed in a future version.
Instructions for updating:
The old _FeatureColumn APIs are being deprecated. Please use the new FeatureColumn APIs instead.
WARNING:tensorflow:From C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\feature_column\feature_column_v2.py:4331: VocabularyListCategoricalColumn._num_buckets (from tensorflow.python.feature_column.feature_column_v2) is deprecated and will be removed in a future version.
Instructions for updating:
The old _FeatureColumn APIs are being deprecated. Please use the new FeatureColumn APIs instead.
WARNING:tensorflow:From C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_estimator\python\estimator\canned\linear.py:308: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.cast` instead.
WARNING:tensorflow:From C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\keras\optimizer_v2\ftrl.py:143: calling Constant.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
2020-01-03 19:10:35.759525: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2020-01-03 19:10:35.894359: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: GeForce MX150 major: 6 minor: 1 memoryClockRate(GHz): 1.0375
pciBusID: 0000:02:00.0
2020-01-03 19:10:35.894607: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2020-01-03 19:10:35.898315: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2020-01-03 19:10:37.034419: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-01-03 19:10:37.034645: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165] 0
2020-01-03 19:10:37.034780: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0: N
2020-01-03 19:10:37.035817: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1356 MB memory) -> physical GPU (device: 0, name: GeForce MX150, pci bus id: 0000:02:00.0, compute capability: 6.1)
Traceback (most recent call last):
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\client\session.py", line 305, in __init__
fetch, allow_tensor=True, allow_operation=True))
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\framework\ops.py", line 3607, in as_graph_element
return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\framework\ops.py", line 3699, in _as_graph_element_locked
(type(obj).__name__, types_str))
TypeError: Can not convert a int64 into a Tensor or Operation.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/bueny/PycharmProjects/untitled3/MinimalLinearFile.py", line 58, in <module>
linear_est.train(train_input_fn, max_steps=100)
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 370, in train
loss = self._train_model(input_fn, hooks, saving_listeners)
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 1160, in _train_model
return self._train_model_default(input_fn, hooks, saving_listeners)
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 1194, in _train_model_default
saving_listeners)
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py", line 1489, in _train_with_estimator_spec
log_step_count_steps=log_step_count_steps) as mon_sess:
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\training\monitored_session.py", line 584, in MonitoredTrainingSession
stop_grace_period_secs=stop_grace_period_secs)
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\training\monitored_session.py", line 1014, in __init__
stop_grace_period_secs=stop_grace_period_secs)
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\training\monitored_session.py", line 725, in __init__
self._sess = _RecoverableSession(self._coordinated_creator)
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\training\monitored_session.py", line 1207, in __init__
_WrappedSession.__init__(self, self._create_session())
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\training\monitored_session.py", line 1212, in _create_session
return self._sess_creator.create_session()
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\training\monitored_session.py", line 885, in create_session
hook.after_create_session(self.tf_sess, self.coord)
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\training\basic_session_run_hooks.py", line 580, in after_create_session
self._save(session, global_step)
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\training\basic_session_run_hooks.py", line 611, in _save
self._get_saver().save(session, self._save_path, global_step=step)
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\training\saver.py", line 1149, in save
global_step = training_util.global_step(sess, global_step)
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\training\training_util.py", line 68, in global_step
return int(sess.run(global_step_tensor))
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\client\session.py", line 956, in run
run_metadata_ptr)
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\client\session.py", line 1165, in _run
self._graph, fetches, feed_dict_tensor, feed_handles=feed_handles)
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\client\session.py", line 474, in __init__
self._fetch_mapper = _FetchMapper.for_fetch(fetches)
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\client\session.py", line 276, in for_fetch
return _ElementFetchMapper(fetches, contraction_fn)
File "C:\Users\bueny\.conda\envs\TensorFlow\lib\site-packages\tensorflow_core\python\client\session.py", line 309, in __init__
(fetch, type(fetch), str(e)))
TypeError: Fetch argument 0 has invalid type <class 'numpy.int64'>, must be a string or Tensor. (Can not convert a int64 into a Tensor or Operation.)
提前非常感谢您,
本杰明
最佳答案
我能够从 TF's Boosted_Trees Estimator example 重现正确的结果如下(不对其代码进行任何修改):
我猜您可能会收到错误,主要是因为安装了不正确的 TensorFlow(或其他依赖项)版本。
导入后在终端中运行tf.__version__
来检查您正在使用的tensorflow版本。
希望这有帮助!
关于python - TensorFlow 2.0 : Cant run minimal TF Tutorial: TypeError: Can not convert a int64 into a Tensor or Operation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59586949/
在 Tensorflow(从 v1.2.1 开始)中,似乎有(至少)两个并行 API 来构建计算图。 tf.nn 中有函数,如 conv2d、avg_pool、relu、dropout,tf.laye
我正在处理眼睛轨迹数据和卷积神经网络。我被要求使用 tf.reduce_max(lastconv, axis=2)代替 MaxPooling 层和 tf.reduce_sum(lastconv,axi
TensorFlow 提供了 3 种不同的数据存储格式 tf.train.Feature .它们是: tf.train.BytesList tf.train.FloatList tf.train.In
我正在尝试为上下文强盗问题 (https://medium.com/emergent-future/simple-reinforcement-learning-with-tensorflow-part
我在使用 Tensorflow 时遇到问题: 以下代码为卷积 block 生成正确的图: def conv_layer(self, inputs, filter_size = 3, num_filte
我正在将我的训练循环迁移到 Tensorflow 2.0 API .在急切执行模式下,tf.GradientTape替换 tf.gradients .问题是,它们是否具有相同的功能?具体来说: 在函数
tensorflow 中 tf.control_dependencies(tf.get_collection(tf.GraphKeys.UPDATE_OPS)) 的目的是什么? 更多上下文:
我一直在努力学习 TensorFlow,我注意到不同的函数用于相同的目标。例如,为了平方变量,我看到了 tf.square()、tf.math.square() 和 tf.keras.backend.
我正在尝试使用自动编码器开发图像着色器。有 13000 张训练图像。如果我使用 tf.data,每个 epoch 大约需要 45 分钟,如果我使用 tf.utils.keras.Sequence 大约
我尝试按照 tensorflow 教程实现 MNIST CNN 神经网络,并找到这些实现 softmax 交叉熵的方法给出了不同的结果: (1) 不好的结果 softmax = tf.nn.softm
其实,我正在coursera上做deeplearning.ai的作业“Art Generation with Neural Style Transfer”。在函数 compute_layer_styl
训练神经网络学习“异或” 我正在尝试使用“批量归一化”,我创建了一个批量归一化层函数“batch_norm1”。 import tensorflow as tf import nump
我正在尝试协调来自 TF“图形和 session ”指南以及 TF“Keras”指南和 TF Estimators 指南的信息。现在在前者中它说 tf.Session 使计算图能够访问物理硬件以执行图
我正在关注此处的多层感知器示例:https://github.com/aymericdamien/TensorFlow-Examples我对函数 tf.nn.softmax_cross_entropy
回到 TensorFlow = 2.0 中消失了。因此,像这样的解决方案...... with tf.variable_scope("foo"): with tf.variable_scope
我按照官方网站中的步骤安装了tensorflow。但是,在该网站中,作为安装的最后一步,他们给出了一行代码来“验证安装”。但他们没有告诉这段代码会给出什么输出。 该行是: python -c "imp
代码: x = tf.constant([1.,2.,3.], shape = (3,2,4)) y = tf.constant([1.,2.,3.], shape = (3,21,4)) tf.ma
我正在尝试从 Github 训练一个 3D 分割网络.我的模型是用 Keras (Python) 实现的,这是一个典型的 U-Net 模型。模型,总结如下, Model: "functional_3"
我正在使用 TensorFlow 2。我正在尝试优化一个函数,该函数使用经过训练的 tensorflow 模型(毒药)的损失。 @tf.function def totalloss(x): x
试图了解 keras 优化器中的 SGD 优化代码 (source code)。在 get_updates 模块中,我们有: # momentum shapes = [K.int_shape(p) f
我是一名优秀的程序员,十分优秀!