Skip to content

pr_curve_streaming_op creates duplicate graphs with offset of one step #965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alienczf opened this issue Feb 10, 2018 · 0 comments
Closed
Assignees

Comments

@alienczf
Copy link

alienczf commented Feb 10, 2018

I believe submitting both the stats tensors and op to tf.summary.tensor_summary creates duplicate plots
image

    def compute_summary(tp, fp, tn, fn, collections):
      precision = tp / tf.maximum(_MINIMUM_COUNT, tp + fp)
      recall = tp / tf.maximum(_MINIMUM_COUNT, tp + fn)

      return _create_tensor_summary(
          name,
          tp,
          fp,
          tn,
          fn,
          precision,
          recall,
          num_thresholds,
          display_name,
          description,
          collections)

    pr_curve = compute_summary(tp, fp, tn, fn, metrics_collections)
    update_op = compute_summary(update_tp, update_fp, update_tn, update_fn,
                                updates_collections)

    return pr_curve, update_op

I have made a quick fix that looks like this:

    def compute_summary(tp, fp, tn, fn, collections):
      precision = tp / tf.maximum(_MINIMUM_COUNT, tp + fp)
      recall = tp / tf.maximum(_MINIMUM_COUNT, tp + fn)

      return tf.stack([
        tf.cast(tp, tf.float32),
        tf.cast(fp, tf.float32),
        tf.cast(tn, tf.float32),
        tf.cast(fn, tf.float32),
        tf.cast(precision, tf.float32),
        tf.cast(recall, tf.float32)
      ])

    pr_curve = tf.summary.tensor_summary(
      name='pr_curves',
      tensor=compute_summary(tp, fp, tn, fn, metrics_collections),
      collections=metrics_collections,
      summary_metadata=metadata.create_summary_metadata(
        display_name=display_name if display_name is not None else name,
        description=description or '',
        num_thresholds=num_thresholds
      )
    )

    update_op = compute_summary(update_tp, update_fp, update_tn, update_fn,
                                updates_collections)

    return pr_curve, update_op

This removes the duplicate plot but most of the code are a bad code duplication.

Will appreciate any recommendations for fix without code change or maybe a cleaner fix to be committed for pr curves

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants