§
    -P„jP0  ã                   ó  — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ g d	¢Zej        Zej        Zej        Zej        Zej        Zej        ZdZd
ddddddeddddfd„Zd
dddddddeddddddddfd„ZdS )a¼  Contains functions for evaluation and summarization of metrics.

The evaluation.py module contains helper functions for evaluating TensorFlow
modules using a variety of metrics and summarizing the results.

**********************
* Evaluating Metrics *
**********************

In the simplest use case, we use a model to create the predictions, then specify
the metrics and choose one model checkpoint, finally call the`evaluation_once`
method:

  # Create model and obtain the predictions:
  images, labels = LoadData(...)
  predictions = MyModel(images)

  # Choose the metrics to compute:
  names_to_values, names_to_updates = slim.metrics.aggregate_metric_map({
      "accuracy": slim.metrics.accuracy(predictions, labels),
      "mse": slim.metrics.mean_squared_error(predictions, labels),
  })

  checkpoint_path = '/tmp/my_model_dir/my_checkpoint'
  log_dir = '/tmp/my_model_eval/'

  initial_op = tf.group(
      tf.compat.v1.global_variables_initializer(),
      tf.compat.v1.local_variables_initializer())

  metric_values = slim.evaluate_once(
      master='',
      checkpoint_path=checkpoint_path,
      log_dir=log_dir,
      num_evals=1,
      initial_op=initial_op,
      eval_op=names_to_updates.values(),
      final_op=name_to_values.values())

  for metric, value in zip(names_to_values.keys(), metric_values):
    logging.info('Metric %s has value: %f', metric, value)

************************************************
* Evaluating a Checkpointed Model with Metrics *
************************************************

Often, one wants to evaluate a model checkpoint saved on disk. This can be
performed once or repeatedly on a set schedule.

To evaluate a particular model, users define zero or more metrics and zero or
more summaries and call the evaluation_loop method:

  # Create model and obtain the predictions:
  images, labels = LoadData(...)
  predictions = MyModel(images)

  # Choose the metrics to compute:
  names_to_values, names_to_updates = slim.metrics.aggregate_metric_map({
      "accuracy": slim.metrics.accuracy(predictions, labels),
      "mse": slim.metrics.mean_squared_error(predictions, labels),
  })

  # Define the summaries to write:
  for metric_name, metric_value in metrics_to_values.iteritems():
    tf.compat.v1.summary.scalar(metric_name, metric_value)

  checkpoint_dir = '/tmp/my_model_dir/'
  log_dir = '/tmp/my_model_eval/'

  # We'll evaluate 1000 batches:
  num_evals = 1000

  # Evaluate every 10 minutes:
  slim.evaluation_loop(
      '',
      checkpoint_dir,
      logdir,
      num_evals=num_evals,
      eval_op=names_to_updates.values(),
      summary_op=tf.compat.v1.summary.merge(summary_ops),
      eval_interval_secs=600)

**************************************************
* Evaluating a Checkpointed Model with Summaries *
**************************************************

At times, an evaluation can be performed without metrics at all but rather
with only summaries. The user need only leave out the 'eval_op' argument:

  # Create model and obtain the predictions:
  images, labels = LoadData(...)
  predictions = MyModel(images)

  # Define the summaries to write:
  tf.compat.v1.summary.scalar(...)
  tf.compat.v1.summary.histogram(...)

  checkpoint_dir = '/tmp/my_model_dir/'
  log_dir = '/tmp/my_model_eval/'

  # Evaluate once every 10 minutes.
  slim.evaluation_loop(
      master='',
      checkpoint_dir,
      logdir,
      num_evals=1,
      summary_op=tf.compat.v1.summary.merge(summary_ops),
      eval_interval_secs=600)

é    )Úabsolute_import)Údivision)Úprint_function)Ú
evaluation)Úsummary)Úmonitored_session)Úsaver)ÚStopAfterNEvalsHookÚSummaryAtEndHookÚcheckpoints_iteratorÚevaluate_onceÚevaluation_loopÚget_or_create_eval_stepÚwait_for_new_checkpointé   Nc                 ó‚  — |
t           k    rt          j        ¦   «         }
t          j        |¦  «        g}|
�*|                     t          j        ||
|¬¦  «        ¦  «         |�|                     |¦  «         d}|�t          j	        |¦  «        }t          j
        || t          j        |||¬¦  «        ||||	||¬¦	  «	        S )a	  Evaluates the model at the given checkpoint path.

  Args:
    master: The BNS address of the TensorFlow master.
    checkpoint_path: The path to a checkpoint to use for evaluation.
    logdir: The directory where the TensorFlow summaries are written to.
    num_evals: The number of times to run `eval_op`.
    initial_op: An operation run at the beginning of evaluation.
    initial_op_feed_dict: A feed dictionary to use when executing `initial_op`.
    eval_op: A operation run `num_evals` times.
    eval_op_feed_dict: The feed dictionary to use when executing the `eval_op`.
    final_op: An operation to execute after all of the `eval_op` executions. The
      value of `final_op` is returned.
    final_op_feed_dict: A feed dictionary to use when executing `final_op`.
    summary_op: The summary_op to evaluate after running TF-Slims metric ops. By
      default the summary_op is set to tf.compat.v1.summary.merge_all().
    summary_op_feed_dict: An optional feed dictionary to use when running the
      `summary_op`.
    variables_to_restore: A list of TensorFlow variables to restore during
      evaluation. If the argument is left as `None` then
      slim.variables.GetVariablesToRestore() is used.
    session_config: An instance of `tf.compat.v1.ConfigProto` that will be used
      to configure the `Session`. If left as `None`, the default will be used.
    hooks: A list of additional `SessionRunHook` objects to pass during the
      evaluation.

  Returns:
    The value of `final_op` or `None` if `final_op` is `None`.
  N©Úlog_dirÚ
summary_opÚ	feed_dict)Úinit_opÚinit_feed_dictr	   )ÚmasterÚscaffoldÚeval_opsr   Ú	final_opsÚfinal_ops_feed_dictÚhooksÚconfig)Ú_USE_DEFAULTr   Ú	merge_allr   r
   Úappendr   ÚextendÚtf_saverÚSaverr   r   ÚScaffold)r   Úcheckpoint_pathÚlogdirÚ	num_evalsÚ
initial_opÚinitial_op_feed_dictÚeval_opÚeval_op_feed_dictÚfinal_opÚfinal_op_feed_dictr   Úsummary_op_feed_dictÚvariables_to_restoreÚsession_configr   Ú	all_hooksr	   s                    úW/root/disk_3tb/conda_envs/Huy-visual/lib/python3.11/site-packages/tf_slim/evaluation.pyr   r       sü   € ðX •<ÒÐÝÔ"Ñ$Ô$€Jõ Ô$ YÑ/Ô/ð€)ð ÐØ×ÒÝÔ#ØØ!Ø*ð	,ñ 	,ô 	,ñ-ô -ð -ð
 ÐØ×Ò�UÑÔÐà
€%ØÐ%ÝŒNÐ/Ñ0Ô0€Eå	Ô	!ØØÝ Ô)ØÐ-AÈðPñ Pô PàØ!ØØ,ØØð

ñ 

ô 

ð 
ó    é<   c                 óŒ  — |t           k    rt          j        ¦   «         }t          j        |¦  «        g}|�*|                     t          j        |||¬¦  «        ¦  «         |�|                     |¦  «         d}|�t          j	        |¦  «        }t          j
        || t          j        ||||¬¦  «        |||	|
||||||¬¦  «        S )aã  Runs TF-Slim's Evaluation Loop.

  Args:
    master: The BNS address of the TensorFlow master.
    checkpoint_dir: The directory where checkpoints are stored.
    logdir: The directory where the TensorFlow summaries are written to.
    num_evals: The number of times to run `eval_op`.
    initial_op: An operation run at the beginning of evaluation.
    initial_op_feed_dict: A feed dictionary to use when executing `initial_op`.
    init_fn: An optional callable to be executed after `init_op` is called. The
      callable must accept one argument, the session being initialized.
    eval_op: A operation run `num_evals` times.
    eval_op_feed_dict: The feed dictionary to use when executing the `eval_op`.
    final_op: An operation to execute after all of the `eval_op` executions. The
      value of `final_op` is returned.
    final_op_feed_dict: A feed dictionary to use when executing `final_op`.
    summary_op: The summary_op to evaluate after running TF-Slims metric ops. By
      default the summary_op is set to tf.compat.v1.summary.merge_all().
    summary_op_feed_dict: An optional feed dictionary to use when running the
      `summary_op`.
    variables_to_restore: A list of TensorFlow variables to restore during
      evaluation. If the argument is left as `None` then
      slim.variables.GetVariablesToRestore() is used.
    eval_interval_secs: The minimum number of seconds between evaluations.
    max_number_of_evaluations: the max number of iterations of the evaluation.
      If the value is left as 'None', the evaluation continues indefinitely.
    session_config: An instance of `tf.compat.v1.ConfigProto` that will be used
      to configure the `Session`. If left as `None`, the default will be used.
    timeout: The maximum amount of time to wait between checkpoints. If left as
      `None`, then the process will wait indefinitely.
    timeout_fn: Optional function to call after a timeout.  If the function
      returns True, then it means that no new checkpoints will be generated and
      the iterator will exit.  The function is called with no arguments.
    hooks: A list of additional `SessionRunHook` objects to pass during repeated
      evaluations.

  Returns:
    The value of `final_op` or `None` if `final_op` is `None`.
  Nr   )r   r   Úinit_fnr	   )r   r   r   r   r   r   Úeval_interval_secsr   r   Úmax_number_of_evaluationsÚtimeoutÚ
timeout_fn)r    r   r!   r   r
   r"   r   r#   r$   r%   Úevaluate_repeatedlyr   r&   )r   Úcheckpoint_dirr(   r)   r*   r+   r8   r,   r-   r.   r/   r   r0   r1   r9   r:   r2   r;   r<   r   r3   r	   s                         r4   r   r   í   s  € ðv •<ÒÐÝÔ"Ñ$Ô$€Jõ Ô$ YÑ/Ô/ð€)ð ÐØ×ÒÝÔ#ØØ!Ø*ð	,ñ 	,ô 	,ñ-ô -ð -ð Ðà×Ò�UÑÔÐà
€%ØÐ%ÝŒNÐ/Ñ0Ô0€Eå	Ô	'ØØÝ Ô)ØØ-ØØð	ñ ô ð
 Ø!ØØ,Ø+ØØØ 9ØØð#
ñ 
ô 
ð r5   )Ú__doc__Ú
__future__r   r   r   Útf_slim.trainingr   Útensorflow.python.summaryr   Útensorflow.python.trainingr   r	   r$   Ú__all__r
   r   r=   r   r   r   r    r   r   © r5   r4   ú<module>rF      sx  ðð"mð mð^ 'Ð &Ð &Ð &Ð &Ð &Ø Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %à 'Ð 'Ð 'Ð 'Ð 'Ð 'à -Ð -Ð -Ð -Ð -Ð -Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8ðð ð €ð !Ô4Ð ØÔ.Ð Ø Ô4Ð à$Ô<Ð Ø$Ô<Ð Ø!Ô6Ð à€ð Ø!Ø'+ØØ$(ØØ%)Ø)Ø'+Ø'+Ø!%ØðJð Jð Jð Jð`  Ø#Ø)-Ø Ø Ø&*Ø!Ø'+Ø+Ø)-Ø)-Ø')Ø.2Ø#'Ø Ø#Øð'bð bð bð bð bð br5   