我正在ML引擎上训练自定义tensorflow估计器,并遇到以下错误:
The replica master 0 exited with a non-zero status of 11(SIGSEGV)
Run Code Online (Sandbox Code Playgroud)
唯一的其他错误日志是:
Command '['python3', '-m', 'train_model.train', ... ']' returned non-zero exit status -11
Run Code Online (Sandbox Code Playgroud)
不再有追溯,因此我只需要继续执行此“无效的内存引用或分段错误代码 ”。
此SIGSEGV错误并不总是发生。一些培训作业运行没有问题,另一些则在4小时后抛出此错误,而另一些在15分钟后抛出。
我已经对估算器培训代码的各个部分进行了尝试,尝试通过尝试和尝试错误的方法找到原因,但是没有成功。
我以为11代码可以对应于该错误代码在谷歌的API,发现许多人都经历过 OutOfSequence,并OutOfRange在估计使用自定义指标时错误EvalSpec,但我不认为这是在这里造成的错误,因为我使用tf.metric。
我正在使用BASIC扩展层,并查看CPU利用率,它从未超过80%,而内存利用率图显示了大约25%。
我正在缓存tensorflow数据集,但是当不缓存数据集时也会收到此错误。在运行train_and_evaluate方法以及方法时都会发生错误train。
关于如何在培训工作中查找此崩溃的路线原因,有什么建议吗?或导致崩溃的一些常见原因是什么?解决方案是否只是使用更大的内存计算机?
我试图像这样在估算器的eval_metric_ops中添加r的平方:
def model_fn(features, labels, mode, params):
predict = prediction(features, params, mode)
loss = my_loss_fn
eval_metric_ops = {
'rsquared': tf.subtract(1.0, tf.div(tf.reduce_sum(tf.squared_difference(label, tf.reduce_sum(tf.squared_difference(labels, tf.reduce_mean(labels)))),
name = 'rsquared')
}
train_op = tf.contrib.layers.optimize_loss(
loss = loss,
global_step = global_step,
learning_rate = 0.1,
optimizer = "Adam"
)
predictions = {"predictions": predict}
return tf.estimator.EstimatorSpec(
mode = mode,
predictions = predictions,
loss = loss,
train_op = train_op,
eval_metric_ops = eval_metric_ops
)
Run Code Online (Sandbox Code Playgroud)
但我有以下错误:
TypeError:eval_metric_ops的值必须为(metric_value,update_op)元组,给定:键:rsquared的Tensor(“ rsquared:0”,shape =(),dtype = float32)
我也尝试过不使用name参数,但是没有任何改变。您知道如何创建此eval_metric_ops吗?
我会在全球的每一个步骤都蒙受训练损失。但是我确实想在张量板上的图'lossxx'中添加评估损失。怎么做?
类MyHook(tf.train.SessionRunHook):
def after_run(self,run_context,run_value):
_session = run_context.session
_session.run(_session.graph.get_operation_by_name('acc_op'))
def my_model(功能,标签,模式):
...
logits = tf.layers.dense(net,3,激活=无)
预测类= tf.argmax(logits,1)
如果模式== tf.estimator.ModeKeys.PREDICT:
预测= {
'class':predicted_classes,
'问题':tf.nn.softmax(logits)
}
返回tf.estimator.EstimatorSpec(mode,projections = predictions)
#计算损失。
损失= tf.losses.sparse_softmax_cross_entropy(labels =标签,logits = logits)
acc,acc_op = tf.metrics.accuracy(标签=标签,预测= predicted_classes)
tf.identity(acc_op,'acc_op')
loss_sum = tf.summary.scalar('lossxx',loss)
precision_sum = tf.summary.scalar('accuracyxx',acc)
merg = tf.summary.merge_all()
#创建培训项目。
如果mode == tf.estimator.ModeKeys.TRAIN:
优化器= tf.train.AdagradOptimizer(learning_rate = 0.1)
train_op = optimizer.minimize(损失,global_step = tf.train.get_global_step())
返回tf.estimator.EstimatorSpec(mode,loss = loss,train_op = train_op,
training_chief_hooks = [
tf.train.SummarySaverHook(save_steps = 10,output_dir ='。/ model',summary_op = merg)])
返回tf.estimator.EstimatorSpec(
模式,损失=损失,eval_metric_ops = {'accuracy':(acc,acc_op)}
)
classifier.train(input_fn … 我有以下input_fn.
def input_fn(filenames, batch_size):
# Create a dataset containing the text lines.
dataset = tf.data.TextLineDataset(filenames).skip(1)
# Parse each line.
dataset = dataset.map(_parse_line)
# Shuffle, repeat, and batch the examples.
dataset = dataset.shuffle(10000).repeat().batch(batch_size)
# Return the dataset.
return dataset
Run Code Online (Sandbox Code Playgroud)
如果filenames=['file1.csv']或者它很好用filenames=['file2.csv'].它给了我一个错误,如果filenames=['file1.csv', 'file2.csv'].在Tensorflow 文档中,它表示包含一个或多个文件名filenames的tf.string张量.我该如何导入多个文件?
以下是错误.它似乎忽略.skip(1)了input_fn上面的内容:
InvalidArgumentError: Field 0 in record 0 is not a valid int32: row_id
[[Node: DecodeCSV = DecodeCSV[OUT_TYPE=[DT_INT32, DT_INT32, DT_FLOAT, DT_INT32, DT_FLOAT, ..., DT_INT32, DT_INT32, …Run Code Online (Sandbox Code Playgroud) tensorflow tensorflow-serving tensorflow-datasets tensorflow-estimator
我是tensorflow的新手。尝试从创建输入管道tfrecords。以下是我的代码段,用于创建批处理并将其输入到my中estimator:
def generate_input_fn(image,label,batch_size=BATCH_SIZE):
logging.info('creating batches...')
dataset = tf.data.Dataset.from_tensors((image, label)) #<-- dataset is 'TensorDataset'
dataset = dataset.repeat().batch(batch_size)
iterator=dataset.make_initializable_iterator()
iterator.initializer
return iterator.get_next()
Run Code Online (Sandbox Code Playgroud)
该行iterator=dataset.make_initializable_iterator():
ValueError:Tensor(“ count:0”,shape =(),dtype = int64,device = / device:CPU:0)必须与Tensor(“ TensorDataset:0”,shape =(),dtype =变体)。
我认为我不小心使用了来自不同图形的张量,但是我不知道如何以及在哪一行代码中使用。我不知道哪个张量是count:0 或哪个张量是TensorDataset:0。
谁能帮我调试一下。
错误日志:
File "task.py", line 189, in main
estimator.train(input_fn=lambda:generate_input_fn(image=image_data, label=label_data),steps=3,hooks=[logging_hook])
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/estimator.py", line 352, 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 809, in _train_model
input_fn, model_fn_lib.ModeKeys.TRAIN))
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/estimator/estimator.py", line 668, in _get_features_and_labels_from_input_fn
result = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用生成器训练一个估计器,但是我想为该估计器提供每次迭代的样本包。我显示代码:
def _generator():
for i in range(100):
feats = np.random.rand(4,2)
labels = np.random.rand(4,1)
yield feats, labels
def input_func_gen():
shapes = ((4,2),(4,1))
dataset = tf.data.Dataset.from_generator(generator=_generator,
output_types=(tf.float32, tf.float32),
output_shapes=shapes)
dataset = dataset.batch(4)
# dataset = dataset.repeat(20)
iterator = dataset.make_one_shot_iterator()
features_tensors, labels = iterator.get_next()
features = {'x': features_tensors}
return features, labels
x_col = tf.feature_column.numeric_column(key='x', shape=(4,2))
es = tf.estimator.LinearRegressor(feature_columns=[x_col],model_dir=tf_data)
es = es.train(input_fn=input_func_gen,steps = None)
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,它将引发以下错误:
raise ValueError(err.message)
ValueError: Dimensions must be equal, but are 2 and 3 for 'linear/head/labels/assert_equal/Equal' (op: 'Equal') with input shapes: …Run Code Online (Sandbox Code Playgroud) 我已经使用了tensorflow一段时间了。一开始我有这样的东西:
def myModel(training):
with tf.scope_variables('model', reuse=not training):
do model
return model
training_model = myModel(True)
validation_model = myModel(False)
Run Code Online (Sandbox Code Playgroud)
主要是因为我从一些MOOC开始,使我很难做到这一点。但是他们也没有使用TFRecords或Queues。而且我不知道为什么要使用两个单独的模型。我尝试仅构建一个,并使用feed_dict:填充数据:一切正常。
自从我通常只使用一种模型。我的输入始终是place_holders,而我只输入培训或验证数据。
最近,我注意到在使用tf.layers.dropout和的模型上有一些奇怪的行为tf.layers.batch_normalization。这两个函数都有一个我与tf.bool占位符一起使用的“训练”参数。我已经看到tf.layers通常与一起使用tf.estimator.Estimator,但是我没有使用它。我已经阅读了Estimators代码,它似乎为培训和验证创建了两个不同的图形。这些问题可能是由于没有两个单独的模型而引起的,但我仍然持怀疑态度。
是否有明确的原因我没有看到这意味着必须使用两个单独的等效模型?
python machine-learning cross-validation tensorflow tensorflow-estimator
如何global_step从完成tf.estimator.Estimator后获得最后一个train(...)?例如,可以像这样建立一个典型的基于Estimator的训练例程:n_epochs = 10 model_dir ='/ path / to / model_dir'
def model_fn(features, labels, mode, params):
# some code to build the model
pass
def input_fn():
ds = tf.data.Dataset() # obviously with specifying a data source
# manipulate the dataset
return ds
run_config = tf.estimator.RunConfig(model_dir=model_dir)
estimator = tf.estimator.Estimator(model_fn=model_fn, config=run_config)
for epoch in range(n_epochs):
estimator.train(input_fn=input_fn)
# Now I want to do something which requires to know the last global step, how to get it?
my_custom_eval_method(global_step)
Run Code Online (Sandbox Code Playgroud)
仅该 …
我正在尝试使用预制的估计器tf.estimator.DNNClassifier在 MNIST 数据集上使用。我从tensorflow_dataset.
我遵循以下四个步骤:首先构建数据集管道并定义输入函数:
## Step 1
mnist, info = tfds.load('mnist', with_info=True)
ds_train_orig, ds_test = mnist['train'], mnist['test']
def train_input_fn(dataset, batch_size):
dataset = dataset.map(lambda x:({'image-pixels':tf.reshape(x['image'], (-1,))},
x['label']))
return dataset.shuffle(1000).repeat().batch(batch_size)
Run Code Online (Sandbox Code Playgroud)
然后,在步骤 2 中,我使用单个键和形状 784 定义特征列:
## Step 2:
image_feature_column = tf.feature_column.numeric_column(key='image-pixels',
shape=(28*28))
image_feature_column
NumericColumn(key='image-pixels', shape=(784,), default_value=None, dtype=tf.float32, normalizer_fn=None)
Run Code Online (Sandbox Code Playgroud)
第 3 步,我将估算器实例化如下:
## Step 3:
dnn_classifier = tf.estimator.DNNClassifier(
feature_columns=image_feature_column,
hidden_units=[16, 16],
n_classes=10)
Run Code Online (Sandbox Code Playgroud)
最后,通过调用.train()方法使用估计器的步骤 4 :
## Step 4:
dnn_classifier.train(
input_fn=lambda:train_input_fn(ds_train_orig, batch_size=32),
#lambda:iris_data.train_input_fn(train_x, train_y, args.batch_size),
steps=20)
Run Code Online (Sandbox Code Playgroud)
但这会导致以下错误。看起来问题出在数据集上。
--------------------------------------------------------------------------- …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Tensorflow 2.0 在 Google 的 Colab 中训练模型。然而,训练并没有完成它的第一个 epoch。计步器已达到“未知”的 9144(并且仍在继续):
为什么显示消息“未知”?
这是我的顺序模型:
谢谢你的帮助。
keras tensorflow google-colaboratory tensorflow-estimator tensorflow2.0