python - 在张量流中拟合 RNN 估计器
问题描述
我正在尝试使用RNNEstimator()
该类训练 TF 估计器,但在定义估计器时遇到了麻烦。我的目标如下:
- 创建一个 tf.data.Dataset。
- 将其输入 RNN 估计器。
第一部分似乎工作正常。我定义
def _parse_func(record):
# takes tf record as input and returns the following tensors
# numeric_tensor.shape = (5,170) and y.shape=()
return {'numerical': numeric_tensor,}, y
def input_fn(filenames=['data.tfrecord']):
# Returns parsed tf record i.e. the tf.data.Dataset
dataset = tf.data.TFRecordDataset(filenames=filenames)
dataset = dataset.map(map_func=_parse_func)
dataset = dataset.repeat()
dataset = dataset.batch(batch_size=BATCH_SIZE)
return dataset
现在让我们进入肉质部分。
估算器负责创建会话和图形。因此,我只需按以下格式创建估算器:
# create the column
column = tf.contrib.feature_column.sequence_numeric_column('numerical')
# create the estimator
estimator = RNNEstimator(
head=tf.contrib.estimator.regression_head(),
sequence_feature_columns=[column],
num_units=[32, 16], cell_type='lstm')
# train the estimator
estimator.train(input_fn=input_fn, steps=100)
但是,这不起作用。它给了我各种各样的错误!特别是,目前我得到:
TypeError:输入必须是 SparseTensor。
此外,我似乎无法将损失更改为对数损失。我尝试通过使用以下方法将其传递给 head 参数来设置它:
head = tf.contrib.estimator.regression_head(loss_fn=tf.losses.log_loss)
解决方案
推荐阅读
- tomcat - 在 Windows 服务器上访问被拒绝的启动 tomcat 服务的权限
- java - Apache HttpClient Max-Connections-per-host 行为
- github - 如果您从该项目中删除,您是否会失去该项目的贡献?
- android - 手动更改时钟时的 Amazon CloudFront 握手异常
- javascript - 无法通过 HTML 页面接收来自 Express 服务器的响应
- winforms - 按钮触发的 Get-ADUser
- mysql - MYSQL:从传递 2 列值的表中选择:st_distance_sphere 的参数不正确
- asp.net-core - 对钥匙圈中的钥匙感到困惑
- c# - 即使 web.config 中有所需的属性,Web 应用程序也会出现 413 错误
- angular2-services - 是否可以在 Angular 2 版本中将 protobuf 数据转换为 json