2017-08-07 5 views
0

Ich habe eine Iterator-Funktion, die einen Stapel von Features und Label als ein Tupel von numpy Arrays liefert.Wie Feed-Iterator von Numpy-Array zu Tensorflow Estimator/Evaluable

def batch_iter(): für ...: Ausbeute (np_features, np_labels)

und dann versuche ich wie

# the cnn_model_fn will print out shapes of various tensor when 
# constructing the model 
classifier = learn.Estimator(
    model_fn=cnn_model_fn, model_dir="/tmp/convnet_model") 
for train_data, train_labels in batch_iter(): 
    classifier.fit(
     input_fn=lambda: (tf.constant(train_data), tf.constant(train_labels)), 
     steps=1, 
     monitors=[logging_hook]) 

Die (kommentierten) log sieht den Tensor Estimator zu füttern wie

conv1 shape (100, 16, 20, 32) 
pool1 shape (100, 8, 10, 32) 
conv2 shape (100, 8, 10, 64) 
pool2 shape (100, 4, 5, 64) 
onehot label shape (100, 5) 
INFO:tensorflow:Create CheckpointSaverHook. 
INFO:tensorflow:Saving checkpoints for 1 into /tmp/convnet_model/model.ckpt. # checkpoint is saved in every iteration 
INFO:tensorflow:step = 1, loss = 1618.76 
INFO:tensorflow:Loss for final step: 1618.76. 
conv1 shape (100, 16, 20, 32) # the model_fn is called in every iteration 
pool1 shape (100, 8, 10, 32) 
conv2 shape (100, 8, 10, 64) 
pool2 shape (100, 4, 5, 64) 
onehot label shape (100, 5) 
INFO:tensorflow:Create CheckpointSaverHook. 
INFO:tensorflow:Restoring parameters from /tmp/convnet_model/model.ckpt-1 # checkpoint is restored in every iteration 
INFO:tensorflow:Saving checkpoints for 2 into /tmp/convnet_model/model.ckpt. 
INFO:tensorflow:step = 2, loss = 69370.6 
INFO:tensorflow:Loss for final step: 69370.6. 
conv1 shape (100, 16, 20, 32) 
pool1 shape (100, 8, 10, 32) 
conv2 shape (100, 8, 10, 64) 
pool2 shape (100, 4, 5, 64) 
onehot label shape (100, 5) 
INFO:tensorflow:Create CheckpointSaverHook. 
INFO:tensorflow:Restoring parameters from /tmp/convnet_model/model.ckpt-2 
INFO:tensorflow:Saving checkpoints for 3 into /tmp/convnet_model/model.ckpt. 
INFO:tensorflow:step = 3, loss = 289303.0 
INFO:tensorflow:Loss for final step: 289303.0. 
... 

Die Stapel werden gelesen, und die Verluste gehen während der Schleife iterieren. Es scheint jedoch so zu sein, dass die Prüfpunkte in jeder Iteration gespeichert und wiederhergestellt werden und die Modell_FN wird in jeder Iteration aufgerufen. Also ich fühle, dass das nicht stimmt.

Wie kann ein Iterator dem Estimator/Evaluable zugeführt werden?

Antwort

1

in Ihrer Eingabe_FN können Sie tf.contrib.training.python_input

verwenden
Verwandte Themen