Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow 不要为估计器的最后一步保存检查点_Tensorflow - Fatal编程技术网

Tensorflow 不要为估计器的最后一步保存检查点

Tensorflow 不要为估计器的最后一步保存检查点,tensorflow,Tensorflow,我使用估计器并在循环中训练模型来提供数据。每一步都是最后一步。检查点也为每个最后步骤保存。我希望避免在每次迭代中保存检查点,以提高培训的性能(速度)。 我找不到任何信息如何做到这一点。你有什么想法/建议/解决方案吗 classifier = Estimator( model_fn=cnn_model_fn, model_dir="./temp_model_Adam", config=tf.contrib.learn.RunConfig( save_chec

我使用估计器并在循环中训练模型来提供数据。每一步都是最后一步。检查点也为每个最后步骤保存。我希望避免在每次迭代中保存检查点,以提高培训的性能(速度)。 我找不到任何信息如何做到这一点。你有什么想法/建议/解决方案吗

classifier = Estimator(
    model_fn=cnn_model_fn,
    model_dir="./temp_model_Adam",
    config=tf.contrib.learn.RunConfig(
        save_checkpoints_secs=None,
        save_checkpoints_steps=100,
        save_summary_steps=None
    )
)



# Train the model

for e in range(0, 10):
    numbers = np.arange(10000)
    np.random.shuffle(numbers)
    for step in range(0, 2000):
        classifier.fit(
            input_fn=lambda: read_images_for_training_as_batch(step, path, 5, numbers),
            steps=1
        )

现在api有了一些变化,但从我看到的情况来看,您错误地使用了fit(当前训练)方法,您应该将steps=2000,并让您的输入函数在数据集上返回一个迭代器。今天,您可以使用tf.estimator.inputs.numpy_input_fn来处理小数据集,否则您必须使用tf.data.DataSet api

类似这样的内容(它加载.wav文件):

from tensorflow.contrib.framework.python.ops import audio_ops as contrib_audio
from tensorflow.python.ops import io_ops
# ...
def input_fn(num_epochs, batch_size, shuffle=False, mode='training')

    def input_fn_bound():
        def _read_file(fn, label):
            return io_ops.read_file(fn), label

        def _decode(data, label):
            pcm = contrib_audio.decode_wav(data,
                                           desired_channels=1,
                                           desired_samples=desired_samples)
            return pcm.audio, label

        filenames = get_files(mode)
        classes = get_classes(mode)
        labels = {'class': np.array(classes)}
        dataset = tf.data.Dataset.from_tensor_slices((filenames, labels))

        if shuffle:
            dataset = dataset.shuffle(buffer_size=len(labels))
        dataset = dataset.map(_read_file, num_parallel_calls=num_map_threads)
        dataset = dataset.map(_decode, num_parallel_calls=num_map_threads)
        dataset = dataset.map(lambda wav, label: ({'wav': wav}, label))

        dataset = dataset.repeat(num_epochs)
        dataset = dataset.batch(batch_size)
        dataset = dataset.prefetch(2)        # To load next batch while the first one is being processed on GPU
        iter = dataset.make_one_shot_iterator()
        features, labels = iter.get_next()
        return features, labels

    return input_fn_bound

# ....

estimator.train(input_fn=input_fn(
        num_epoths=None, 
        batch_size=64,
        shuffle=True,
        mode='training'), 
    steps=10000)