- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试实现一个 TensorFlow DNNRegressor,它使用具有多个标签的张量,但它总是失败并出现我不明白的错误。我在 Tensorflow 1.4.1 上完成了 95% 的测试,然后我刚刚切换到 1.5.0/CUDA 9,但它仍然失败(你知道,我只是希望:))
作为引用,我使用了波士顿示例和 pandas input func 源代码 https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/tutorials/input_fn/boston.py https://github.com/tensorflow/tensorflow/blob/r1.5/tensorflow/python/estimator/inputs/pandas_io.py
在下面的要点中,您可以找到完整的 python 代码、生成的输出、训练数据和(当前未使用的)测试数据。训练数据和测试数据都很小,只是为了构建代码。 https://gist.github.com/anonymous/c3e9fbe5f5faf373fa230909347318cd
错误消息如下(堆栈跟踪是要点,我没有将其发布在这里以避免污染帖子)
tensorflow.python.framework.errors_impl.InvalidArgumentError: assertion failed: [labels shape must be [batch_size, 20]] [Condition x == y did not hold element-wise:] [x (dnn/head/labels/assert_equal/x:0) = ] [20] [y (dnn/head/labels/strided_slice:0) = ] [3] [[Node: dnn/head/labels/assert_equal/Assert/Assert = Assert[T=[DT_STRING, DT_STRING, DT_STRING, DT_INT32, DT_STRING, DT_INT32], summarize=3, _device="/job:localhost/replica:0/task:0/device:CPU:0"](dnn/head/labels/assert_equal/All/_151, dnn/head/labels/assert_equal/Assert/Assert/data_0, dnn/head/labels/assert_equal/Assert/Assert/data_1, dnn/head/labels/assert_equal/Assert/Assert/data_2, dnn/head/logits/assert_equal/x/_153, dnn/head/labels/assert_equal/Assert/Assert/data_4, dnn/head/labels/strided_slice/_155)]]
input_fn 如下
def get_input_fn(dataset,
model_labels=None,
batch_size=128,
num_epochs=1,
shuffle=None,
queue_capacity=1000,
num_threads=1):
dataset = dataset.copy()
if queue_capacity is None:
if shuffle:
queue_capacity = 4 * len(dataset)
else:
queue_capacity = len(dataset)
min_after_dequeue = max(queue_capacity / 4, 1)
def input_fn():
queue = feeding_functions._enqueue_data(
dataset,
queue_capacity,
shuffle=shuffle,
min_after_dequeue=min_after_dequeue,
num_threads=num_threads,
enqueue_size=batch_size,
num_epochs=num_epochs)
if num_epochs is None:
features = queue.dequeue_many(batch_size)
else:
features = queue.dequeue_up_to(batch_size)
assert len(features) == len(dataset.columns) + 1, ('Features should have one '
'extra element for the index.')
features = features[1:]
features = dict(zip(list(dataset.columns), features))
if model_labels is not None:
#labels = tf.stack([features.pop(model_label) for model_label in model_labels], 0);
labels = [features.pop(model_label) for model_label in model_labels]
return features, labels
return features
return input_fn
我能够使用以下输入 fn 进行训练和预测,但看起来不适合处理我稍后想要用于训练的数据量。此外,当我将它与评估方法一起使用时,它会卡住。
def get_input_fn(dataset,
model_labels=None):
def input_fn():
features = {k: tf.constant(len(dataset), shape=[dataset[k].size, 1]) for k in model_features}
if model_labels is not None:
labels_data = []
for i in range(0, len(dataset)):
temp = []
for label in model_labels:
temp.append(dataset[label].values[i])
labels_data.append(temp)
labels = tf.constant(labels_data, shape=[len(dataset), len(model_labels)])
return features, labels
else:
return features
return input_fn
谢谢!
注释:如果您检查要点中的完整代码,您会注意到功能和标签的数量取决于类别的数量,它是根据种子数据动态构建的。也许我可以改用 RNN 并将每个时期映射到一个类别,而不是构建那个巨大的矩阵,但目前我专注于让这个测试工作。
最佳答案
最后我稍微改变了我的生成方法,测试代码已拆分为prepare.py和train.py,prepare.py将数据写入一些CSV(输入数据和类别)和train中.py 我将输入 fn 替换为加载这些 csv、构建数据集、使用 tf.read_csv 解析数据集行(以及更多其他内容)的 fn。
csv_field_defaults = [[0]] * (1 + len(model_features) + len(model_labels))
def _parse_line(line):
fields = tf.decode_csv(line, csv_field_defaults)
# Remove the user id
fields.pop(0)
features = dict(zip(model_features + model_labels,fields))
labels = tf.stack([features.pop(model_label) for model_label in model_labels])
return features, labels
def csv_input_fn(csv_path, batch_size):
dataset = tf.data.TextLineDataset(csv_path).skip(1)
dataset = dataset.map(_parse_line)
dataset = dataset.shuffle(1000).repeat().batch(batch_size)
return dataset.make_one_shot_iterator().get_next()
# Initialize tensor flow
tf.logging.set_verbosity(tf.logging.INFO)
# Initialize the neural network
feature_cols = [tf.feature_column.numeric_column(k) for k in model_features]
regressor = tf.estimator.DNNRegressor(feature_columns=feature_cols,
label_dimension=len(model_labels),
hidden_units=[4096, 2048, 1024, 512],
model_dir="tf_model")
我目前能够处理 10000 条记录,但我需要解析更多数据,希望这个实现表现更好
csv_input_fn
来自 tensorflow 示例,同时我修改了 _parse_line
以根据需要处理功能和标签。
关于python - DNNRegressor 训练输入多个标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48629347/
real adaboost Logit boost discrete adaboost 和 gentle adaboost in train cascade parameter 有什么区别.. -bt
我想为 book crossing 构建训练数据矩阵和测试数据矩阵数据集。但作为 ISBN 代码的图书 ID 可能包含字符。因此,我无法应用此代码(来自 tutorial ): #Create two
我找到了 JavaANPR 库,我想对其进行自定义以读取我所在国家/地区的车牌。 似乎包含的字母表与我们使用的字母表不同 ( http://en.wikipedia.org/wiki/FE-Schri
我有一个信用卡数据集,其中 98% 的交易是非欺诈交易,2% 是欺诈交易。 我一直在尝试在训练和测试拆分之前对多数类别进行欠采样,并在测试集上获得非常好的召回率和精度。 当我仅在训练集上进行欠采样并在
我打算: 在数据集上从头开始训练 NASNet 只重新训练 NASNet 的最后一层(迁移学习) 并比较它们的相对性能。从文档中我看到: keras.applications.nasnet.NASNe
我正在训练用于分割的 uNet 模型。训练模型后,输出全为零,我不明白为什么。 我看到建议我应该使用特定的损失函数,所以我使用了 dice 损失函数。这是因为黑色区域 (0) 比白色区域 (1) 大得
我想为新角色训练我现有的 tesseract 模型。我已经尝试过 上的教程 https://github.com/tesseract-ocr/tesseract/wiki/TrainingTesser
我的机器中有两个 NVidia GPU,但我没有使用它们。 我的机器上运行了三个神经网络训练。当我尝试运行第四个时,脚本出现以下错误: my_user@my_machine:~/my_project/
我想在python的tensorflow中使用稀疏张量进行训练。我找到了很多代码如何做到这一点,但没有一个有效。 这里有一个示例代码来说明我的意思,它会抛出一个错误: import numpy as
我正在训练一个 keras 模型,它的最后一层是单个 sigmoid单元: output = Dense(units=1, activation='sigmoid') 我正在用一些训练数据训练这个模型
所以我需要使用我自己的数据集重新训练 Tiny YOLO。我正在使用的模型可以在这里找到:keras-yolo3 . 我开始训练并遇到多个优化器错误,添加了错误代码以防止混淆。 我注意到即使它应该使用
将 BERT 模型中的标记化范式更改为其他东西是否有意义?也许只是一个简单的单词标记化或字符级标记化? 最佳答案 这是论文“CharacterBERT: Reconciling ELMo and BE
假设我有一个非常简单的神经网络,比如多层感知器。对于每一层,激活函数都是 sigmoid 并且网络是全连接的。 在 TensorFlow 中,这可能是这样定义的: sess = tf.Inte
有没有办法在 PyBrain 中保存和恢复经过训练的神经网络,这样我每次运行脚本时都不必重新训练它? 最佳答案 PyBrain 的神经网络可以使用 python 内置的 pickle/cPickle
我尝试使用 Keras 训练一个对手写数字进行分类的 CNN 模型,但训练的准确度很低(低于 10%)并且误差很大。我尝试了一个简单的神经网络,但没有效果。 这是我的代码。 import tensor
我在 Windows 7 64 位上使用 tesseract 3.0.1。我用一种新语言训练图书馆。 我的示例数据间隔非常好。当我为每个角色的盒子定义坐标时,盒子紧贴角色有多重要?我使用其中一个插件,
如何对由 dropout 产生的许多变薄层进行平均?在测试阶段要使用哪些权重?我真的很困惑这个。因为每个变薄的层都会学习一组不同的权重。那么反向传播是为每个细化网络单独完成的吗?这些细化网络之间的权重
我尝试训练超正方语言。我正在使用 Tess4J 进行 OCR 处理。我使用jTessBoxEditor和SerakTesseractTrainer进行训练操作。准备好训练数据后,我将其放在 Tesse
我正在构建一个 Keras 模型,将数据分类为 3000 个不同的类别,我的训练数据由大量样本组成,因此在用一种热编码对训练输出进行编码后,数据非常大(item_count * 3000 * 的大小)
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我是一名优秀的程序员,十分优秀!