- 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/
我正在使用SpringBoot和JPA来调用db,我遇到异常 org.springframework.core.convert.ConverterNotFoundException: No conve
我尝试实现 Spring Converter,但在单元测试中出现错误: Kotlin: Null can not be a value of a non-null type TodoItem 如果我尝
我在 Spring Boot 2.0 示例中使用 Spring Data Redis。在此示例中,我尝试将客户数据 + 学生数据保存在一起。我不太确定这里的数据建模是如何发生的,但假设它与 Mongo
我在 Spring 的 XML 配置文件之一中有以下代码:
我们正在尝试使用 hibernate Converter 来加密/解密通过 hibernate 存储的几列数据 @Convert(attributeName="myattr",converter=Da
我有this我必须实现的功能: protected override ValidationResult IsValid( Object value, ValidationContext
我看到了 std::convert::Into有任何实现 std::convert::From 的实现: impl Into for T where U: From, 在Rust 1.0标准库
Convert.ChangeType 或 Convert.ToInt32 或 int.Parse 之间是否存在性能优势 最佳答案 如果您知道要将 string 转换为 Int32,使用 Convert
我会定期浏览我的家庭作业以供上课。我的扫描仪将原始 jpg 文件导出到 USB,然后我可以从那里使用 gimp 编辑文件并将其另存为 pdf。我发现一种节省时间的方法是将我的多页作业导出为 .mng
Grails版本:2.3.8我在BootStrap.groovy中注册了一个自定义日期编码器,但是当我使用日期填充为Json的Object时,它将引发异常:Exception message is C
我会定期浏览我的家庭作业以供上课。我的扫描仪将原始 jpg 文件导出到 USB,然后我可以从那里使用 gimp 编辑文件并将其另存为 pdf。我发现一种节省时间的方法是将我的多页作业导出为 .mng
我正在尝试制作一个 SKAction,以便我的玩家慢慢地被拉向一个要杀死他的敌人。实际上,问题在于玩家和敌人处于不同的节点,遵循以下层次结构: 场景(SKScene)-PARENT->播放器(SKNo
我通过 xml 设置了 spring data mongo 自定义转换器,如下所示 在自定义读/写转换器中,我想
我正在尝试使用名为 Simple Captcha 的 gem 这需要在机器上安装 ImageMagick。我已经安装了它并且 convert --version 显示了这个 Version: Imag
我正在尝试使用名为 Simple Captcha 的 gem 这需要在机器上安装 ImageMagick。我已经安装了它并且 convert --version 显示了这个 Version: Imag
我正在使用 Spring JPA,我需要有一个 native 查询来调用存储过程。从结果中,我只需要获取两个字段,即代码和消息。我创建了一个包含两个字段代码和消息的类。它不起作用,这是我收到的错误:
我首先有多部分文件,我想将其发送到camel管道并使用原始名称保存该文件。 我的代码: @Autowired ProducerTemplate producerTemplate; ...
我的maven项目使用了spring、hibernate。我得到“没有这样的方法错误”。我相信这是由于依赖项中的版本冲突造成的,但不知道是什么。构建成功。但是在“NetBeans:在 GlassFis
TL;DR:Vaadin 8 中是否有类似于 Vaadin 7 的转换器来更新 UI 中输入字段的表示? IE。在输入字段失去焦点后立即从用户输入中删除所有非数字,或将小数转换为货币? Vaadin
我昨天问了一个问题here关于从匿名对象读取属性并将它们写入类的私有(private)字段。问题解决了。这是一个小故事: 我有一些 json 格式的数据。我将它们反序列化为 ExpandoObject
我是一名优秀的程序员,十分优秀!