o
    2he                     @   s   d Z ddlZejed ejdds)ddlmZ ddl	m
Z ddlmZ n
ddlm
Z dd	 Zed
G dd dZdS )z+This tool analyzes a TensorFlow Lite graph.    Ntflite_runtimeanalyzer)wrap_converter)_pywrap_analyzer_wrapper)	tf_exportc                  O   s   ~ ~dd S )Nc                 S   s   | S )N )xr   r   Z/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorflow/lite/python/analyzer.py<lambda>    s    z_tf_export.<locals>.<lambda>r   )r   kwargsr   r   r	   
_tf_export   s   r   zlite.experimental.Analyzerc                   @   s$   e Zd ZdZe			dddZdS )ModelAnalyzerup  Provides a collection of TFLite model analyzer tools.

  Example:

  ```python
  model = tf.keras.applications.MobileNetV3Large()
  fb_model = tf.lite.TFLiteConverterV2.from_keras_model(model).convert()
  tf.lite.experimental.Analyzer.analyze(model_content=fb_model)
  # === TFLite ModelAnalyzer ===
  #
  # Your TFLite model has ‘1’ subgraph(s). In the subgraph description below,
  # T# represents the Tensor numbers. For example, in Subgraph#0, the MUL op
  # takes tensor #0 and tensor #19 as input and produces tensor #136 as output.
  #
  # Subgraph#0 main(T#0) -> [T#263]
  #   Op#0 MUL(T#0, T#19) -> [T#136]
  #   Op#1 ADD(T#136, T#18) -> [T#137]
  #   Op#2 CONV_2D(T#137, T#44, T#93) -> [T#138]
  #   Op#3 HARD_SWISH(T#138) -> [T#139]
  #   Op#4 DEPTHWISE_CONV_2D(T#139, T#94, T#24) -> [T#140]
  #   ...
  ```

  WARNING: Experimental interface, subject to change.
  NFc                 K   st   | s|st d| rtd|  d | }d}ntd |}d}|ddr/tt|| dS tt||| dS )	a  Analyzes the given tflite_model with dumping model structure.

    This tool provides a way to understand users' TFLite flatbuffer model by
    dumping internal graph structure. It also provides additional features
    like checking GPU delegate compatibility.

    WARNING: Experimental interface, subject to change.
             The output format is not guaranteed to stay stable, so don't
             write scripts to this.

    Args:
      model_path: TFLite flatbuffer model path.
      model_content: TFLite flatbuffer model object.
      gpu_compatibility: Whether to check GPU delegate compatibility.
      **kwargs: Experimental keyword arguments to analyze API.

    Returns:
      Print analyzed report via console output.
    z4neither `model_path` nor `model_content` is providedz=== z ===
Tz=== TFLite ModelAnalyzer ===
Fexperimental_use_mlirN)
ValueErrorprintgetr    wrapped_flat_buffer_file_to_mlir_analyzer_wrapperr   )
model_pathmodel_contentgpu_compatibilityr   tflite_modelinput_is_filepathr   r   r	   analyze?   s(   zModelAnalyzer.analyze)NNF)__name__
__module____qualname____doc__staticmethodr   r   r   r   r	   r   #   s    r   )r   ospathsplitext__file__endswithjoin$tensorflow.compiler.mlir.lite.pythonr   'tensorflow.lite.python.analyzer_wrapperr   r    tensorflow.python.util.tf_exportr   r   r   r   r   r   r   r	   <module>   s   