繁体   English   中英

tf.estimator.Estimator给出了不同的测试精度,当时代的时代与所有时代相比

[英]tf.estimator.Estimator gives different test accuracy when trianed epoch by epoch vs over all epochs

我已经为一个tf.estimator.Estimator定义了一个简单的CNN作为我的model_fn,并用这个input_fn提供它:

 def input_fn(features, labels, batch_size, epochs): dataset = tf.data.Dataset.from_tensor_slices((features)) dataset = dataset.map(lambda x: tf.cond(tf.random_uniform([], 0, 1) > 0.5, lambda: dataset_augment(x), lambda: x), num_parallel_calls=16).cache() dataset_labels = tf.data.Dataset.from_tensor_slices((labels)) dataset = dataset.zip((dataset, dataset_labels)) dataset = dataset.shuffle(30000) dataset = dataset.repeat(epochs) dataset = dataset.batch(batch_size) dataset = dataset.prefetch(-1) return dataset 

当我以这种方式训练估算器时,我在10个时期后获得43%的测试精度:

steps_per_epoch = data_train.shape[0] // batch_size
for epoch in range(1, epochs + 1):
    cifar100_classifier.train(lambda: input_fn(data_train, labels_train, batch_size, epochs=1), steps=steps_per_epoch)

但是当我以这种方式训练时,我在10个时期后获得32%的测试精度:

steps_per_epoch = data_train.shape[0] // batch_size
max_steps = epochs * steps_per_epoch
cifar100_classifier.train(steps=max_steps,
                              input_fn=lambda: input_fn(data_train, labels_train, batch_size, epochs=epochs))

我只是不明白为什么这两种方法会产生不同的结果。 有人可以解释一下吗?

您的模型的权重是随机初始化的吗? 这可能是一个案例。

由于您在第一个示例中多次调用input_fn ,因此您似乎会通过dataset_augment(x)生成更多增强数据,因为您正在为每个x的每个x进行增强投币。

在第二个例子中,你只做一次这些硬币投掷,然后在同一数据上训练多个时期。 所以这里你的火车组有效“小”。

在第一个示例中, .cache()并没有真正地保护您。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM