本文整理汇总了Python中tensorflow.contrib.learn.python.learn.estimators.head._regression_head函数的典型用法代码示例。如果您正苦于以下问题:Python _regression_head函数的具体用法?Python _regression_head怎么用?Python _regression_head使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_regression_head函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testRegression
def testRegression(self):
head = head_lib._regression_head()
with tf.Graph().as_default(), tf.Session() as sess:
prediction = tf.constant([[1.0], [1.0], [3.0]])
labels = tf.constant([[0.0], [1.0], [1.0]])
model_fn_ops = head.head_ops({}, labels, tf.contrib.learn.ModeKeys.TRAIN, _noop_train_op, logits=prediction)
self.assertAlmostEqual(5.0 / 3, sess.run(model_fn_ops.loss))
示例2: testRegression
def testRegression(self):
head = head_lib._regression_head()
with tf.Graph().as_default(), tf.Session() as sess:
prediction = tf.constant([[1.], [1.], [3.]])
targets = tf.constant([[0.], [1.], [1.]])
model_fn_ops = head.head_ops({}, targets,
tf.contrib.learn.ModeKeys.TRAIN,
None, logits=prediction)
self.assertAlmostEqual(5. / 3, sess.run(model_fn_ops.loss))
示例3: testRegressionWithWeights
def testRegressionWithWeights(self):
head = head_lib._regression_head(weight_column_name="label_weight")
with tf.Graph().as_default(), tf.Session() as sess:
features = {"label_weight": tf.constant([[2.0], [5.0], [0.0]])}
prediction = tf.constant([[1.0], [1.0], [3.0]])
labels = tf.constant([[0.0], [1.0], [1.0]])
model_fn_ops = head.head_ops(
features, labels, tf.contrib.learn.ModeKeys.TRAIN, _noop_train_op, logits=prediction
)
self.assertAlmostEqual(2.0 / 3, sess.run(model_fn_ops.loss), places=3)
示例4: testRegression
def testRegression(self):
head = head_lib._regression_head()
with tf.Graph().as_default(), tf.Session():
prediction = tf.constant([[1.], [1.], [3.]])
labels = tf.constant([[0.], [1.], [1.]])
model_fn_ops = head.head_ops({}, labels,
tf.contrib.learn.ModeKeys.TRAIN,
_noop_train_op, logits=prediction)
_assert_no_variables(self)
_assert_metrics(self, 5. / 3, {"loss": 5. / 3}, model_fn_ops)
示例5: testRegressionEvalMode
def testRegressionEvalMode(self):
head = head_lib._regression_head()
with ops.Graph().as_default(), session.Session():
prediction = constant_op.constant([[1.], [1.], [3.]])
labels = constant_op.constant([[0.], [1.], [1.]])
model_fn_ops = head.head_ops(
{}, labels, model_fn.ModeKeys.EVAL, _noop_train_op, logits=prediction)
self.assertIsNone(model_fn_ops.train_op)
_assert_no_variables(self)
_assert_summary_tags(self, ["loss"])
_assert_metrics(self, 5. / 3, {"loss": 5. / 3}, model_fn_ops)
示例6: testErrorInSparseTensorLabels
def testErrorInSparseTensorLabels(self):
head = head_lib._regression_head()
with tf.Graph().as_default():
prediction = tf.constant([[1.0], [1.0], [3.0]])
labels = tf.SparseTensor(
indices=tf.constant([[0, 0], [1, 0], [2, 0]], dtype=tf.int64),
values=tf.constant([0.0, 1.0, 1.0]),
shape=[3, 1],
)
with self.assertRaisesRegexp(ValueError, "SparseTensor is not supported as labels."):
head.head_ops({}, labels, tf.contrib.learn.ModeKeys.TRAIN, _noop_train_op, logits=prediction)
示例7: testRegressionWithLabelName
def testRegressionWithLabelName(self):
label_name = "my_label"
head = head_lib._regression_head(label_name=label_name)
with tf.Graph().as_default(), tf.Session():
prediction = tf.constant([[1.], [1.], [3.]])
labels = {label_name: tf.constant([[0.], [1.], [1.]])}
model_fn_ops = head.head_ops({}, labels,
tf.contrib.learn.ModeKeys.TRAIN,
_noop_train_op, logits=prediction)
_assert_no_variables(self)
_assert_summary_tags(self, ["loss"])
_assert_metrics(self, 5. / 3, {"loss": 5. / 3}, model_fn_ops)
示例8: testRegressionWithLogits
def testRegressionWithLogits(self):
head = head_lib._regression_head()
with ops.Graph().as_default(), session.Session():
model_fn_ops = head.create_model_fn_ops(
{},
labels=((0.,), (1.,), (1.,)),
mode=model_fn.ModeKeys.TRAIN,
train_op_fn=_noop_train_op,
logits=((1.,), (1.,), (3.,)))
_assert_summary_tags(self, ["loss"])
_assert_no_variables(self)
_assert_metrics(self, 5. / 3, {"loss": 5. / 3}, model_fn_ops)
示例9: testErrorInSparseTensorTarget
def testErrorInSparseTensorTarget(self):
head = head_lib._regression_head()
with tf.Graph().as_default():
prediction = tf.constant([[1.], [1.], [3.]])
targets = tf.SparseTensor(
indices=tf.constant([[0, 0], [1, 0], [2, 0]], dtype=tf.int64),
values=tf.constant([0., 1., 1.]),
shape=[3, 1])
with self.assertRaisesRegexp(
ValueError, "SparseTensor is not supported as a target"):
head.head_ops({}, targets, tf.contrib.learn.ModeKeys.TRAIN, None,
logits=prediction)
示例10: testRegressionWithWeights
def testRegressionWithWeights(self):
head = head_lib._regression_head(weight_column_name="label_weight")
with ops.Graph().as_default(), session.Session():
weights = ((2.,), (5.,), (0.,))
model_fn_ops = head.create_model_fn_ops(
features={"label_weight": weights},
labels=((0.,), (1.,), (1.,)),
mode=model_fn.ModeKeys.TRAIN,
train_op_fn=_noop_train_op,
logits=((1.,), (1.,), (3.,)))
_assert_no_variables(self)
_assert_summary_tags(self, ["loss"])
_assert_metrics(self, 2. / len(weights), {"loss": 2. / np.sum(weights)},
model_fn_ops)
示例11: testRegressionWithLogitsInput
def testRegressionWithLogitsInput(self):
head = head_lib._regression_head()
with ops.Graph().as_default(), session.Session():
model_fn_ops = head.create_model_fn_ops(
{},
labels=((0.,), (1.,), (1.,)),
mode=model_fn.ModeKeys.TRAIN,
train_op_fn=_noop_train_op,
logits_input=((0., 0.), (0., 0.), (0., 0.)))
w = ("logits/weights:0", "logits/biases:0")
_assert_variables(
self, expected_global=w, expected_model=w, expected_trainable=w)
variables.global_variables_initializer().run()
_assert_summary_tags(self, ["loss"])
_assert_metrics(self, 2. / 3, {"loss": 2. / 3}, model_fn_ops)
示例12: testRegressionWithWeights
def testRegressionWithWeights(self):
head = head_lib._regression_head(
weight_column_name="label_weight")
with tf.Graph().as_default(), tf.Session():
weights = ((2.,), (5.,), (0.,))
features = {"label_weight": tf.constant(weights)}
prediction = tf.constant([[1.], [1.], [3.]])
labels = tf.constant([[0.], [1.], [1.]])
model_fn_ops = head.head_ops(features, labels,
tf.contrib.learn.ModeKeys.TRAIN,
_noop_train_op, logits=prediction)
_assert_no_variables(self)
_assert_metrics(self, 2. / len(weights), {
"loss": 2. / np.sum(weights)
}, model_fn_ops)
示例13: testRegression
def testRegression(self):
head = head_lib._regression_head()
with tf.Graph().as_default(), tf.Session() as sess:
prediction = tf.constant([[1.], [1.], [3.]])
labels = tf.constant([[0.], [1.], [1.]])
model_fn_ops = head.head_ops({}, labels,
tf.contrib.learn.ModeKeys.TRAIN,
_noop_train_op, logits=prediction)
self._assert_metrics(model_fn_ops)
_assert_no_variables(self)
self.assertAlmostEqual(5. / 3, sess.run(model_fn_ops.loss))
model_fn_ops = head.head_ops({}, labels,
tf.contrib.learn.ModeKeys.EVAL,
_noop_train_op, logits=prediction)
self.assertIsNone(model_fn_ops.train_op)
示例14: testRegressionWithCenteredBias
def testRegressionWithCenteredBias(self):
head = head_lib._regression_head(enable_centered_bias=True)
with tf.Graph().as_default(), tf.Session():
prediction = tf.constant([[1.], [1.], [3.]])
labels = tf.constant([[0.], [1.], [1.]])
model_fn_ops = head.head_ops({}, labels,
tf.contrib.learn.ModeKeys.TRAIN,
_noop_train_op, logits=prediction)
_assert_variables(self, expected_global=(
"centered_bias_weight:0",
"centered_bias_weight/Adagrad:0",
), expected_trainable=(
"centered_bias_weight:0",
))
tf.global_variables_initializer().run()
_assert_metrics(self, 5. / 3, {"loss": 5. / 3}, model_fn_ops)
示例15: testErrorInSparseTensorLabels
def testErrorInSparseTensorLabels(self):
head = head_lib._regression_head()
with ops.Graph().as_default():
prediction = constant_op.constant([[1.], [1.], [3.]])
labels = sparse_tensor.SparseTensor(
indices=constant_op.constant(
[[0, 0], [1, 0], [2, 0]], dtype=dtypes.int64),
values=constant_op.constant([0., 1., 1.]),
dense_shape=[3, 1])
with self.assertRaisesRegexp(ValueError,
"SparseTensor is not supported as labels."):
head.head_ops(
{},
labels,
model_fn.ModeKeys.TRAIN,
_noop_train_op,
logits=prediction)