Thanks for the helpers!
import tensorflow as tf
import numpy as np
modekeys = tf.contrib.learn.ModeKeys
tf.logging.set_verbosity(tf.logging.DEBUG)
class inputExample:
def __init__(self):
self.status = 0.0 # tracing which value was recently 'pushed' to the net
self.model_dir = 'temp_dir'
self.get_estimator()
def input_fn(self):
batch_data = self.reader()
for kk in batch_data.keys():
batch_data[kk] = tf.constant(batch_data[kk])
features_dict = dict(data=batch_data.pop('data'))
labels_dict = batch_data
return features_dict, labels_dict
def model_fn(self, features, labels, mode):
features_in = features['data']
labels_in = labels['labels']
pred_layer = tf.layers.conv2d(name='pred', inputs=features_in, filters=1, kernel_size=3)
tf.summary.scalar(name='label', tensor=tf.squeeze(labels_in))
tf.summary.scalar(name='pred', tensor=tf.squeeze(pred_layer))
loss = None
if mode != modekeys.INFER:
loss = tf.losses.mean_squared_error(labels=labels_in, predictions=pred_layer)
train_op = None
if mode == modekeys.TRAIN:
train_op = tf.contrib.layers.optimize_loss(
loss=loss,
learning_rate = 0.01,
optimizer = 'SGD',
global_step = tf.contrib.framework.get_global_step()
)
predictions = {'estim_exp': pred_layer}
return tf.contrib.learn.ModelFnOps(mode=mode, predictions=predictions, loss=loss, train_op=train_op)
def reader(self):
self.status += 1
return dict(
data = np.ones([1,3,3,1], dtype=np.float32)*self.status,
labels = np.exp(np.ones([1,1,1,1], dtype=np.float32)*self.status)
)
def get_estimator(self):
self.Estimator = tf.contrib.learn.Estimator(
model_fn = self.model_fn,
model_dir = self.model_dir,
config = tf.contrib.learn.RunConfig(
save_checkpoints_steps = 10,
save_summary_steps = 10,
save_checkpoints_secs = None
)
)
if __name__ == '__main__':
ex = inputExample()
ex.Estimator.fit(input_fn=ex.input_fn)
--
You received this message because you are subscribed to the Google Groups "Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss+unsubscribe@tensorflow.org.
To post to this group, send email to dis...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/discuss/152ef246-99e0-4634-8453-70dc5a6733b0%40tensorflow.org.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss+u...@tensorflow.org.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss+unsubscribe@tensorflow.org.
To post to this group, send email to dis...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/discuss/81c59b00-4fb1-484f-943e-4cd130468646%40tensorflow.org.
def input_fn(self):
data, labels = tf.py_func(func=self.input_fn_np(), inp=[], Tout=[tf.float32, tf.float32], stateful=True)
return dict(data=data), dict(labels=labels)
def input_fn_np(self):
batch_data = self.reader()
return batch_data['data'], batch_data['labels']
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/discuss/81c59b00-4fb1-484f-943e-4cd130468646%40tensorflow.org.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss+unsubscribe@tensorflow.org.
To post to this group, send email to dis...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/discuss/098ffc3a-9650-465c-9d09-476e5e687060%40tensorflow.org.
... Tout=[tf.float32, tf.float32] ...
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/discuss/098ffc3a-9650-465c-9d09-476e5e687060%40tensorflow.org.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss+unsubscribe@tensorflow.org.
To post to this group, send email to dis...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/discuss/9e23bf37-f766-4249-a924-1c617d4ef705%40tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/discuss/9e23bf37-f766-4249-a924-1c617d4ef705%40tensorflow.org.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss+unsubscribe@tensorflow.org.
To post to this group, send email to dis...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/discuss/3bcc24ff-a9e4-448e-bad6-349f73d877c2%40tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/discuss/3bcc24ff-a9e4-448e-bad6-349f73d877c2%40tensorflow.org.
To view this discussion on the web visit <a href="https://groups.google.com/a/tensorflow.org/d/msgid/discuss/3bcc24ff-a9e4-448e-bad6-349f73d877c2%40tensorflow.org?utm_medium=email&utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/a/tensorflow.org/d/msgid/discuss/3bcc24ff-a9e4-448e-bad6-349f73d877c2%40tensorflow.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" onclick="this.href='https://groups.google.com/a/tensorflow.org/d/msgid/discuss/3bcc24ff-a9e4
To unsubscribe from this group and stop receiving emails from it, send an email to discuss+unsubscribe@tensorflow.org.
To post to this group, send email to dis...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/discuss/a919217d-07e1-42db-bc05-c91f551bbbbc%40tensorflow.org.