
    &Vf=                     D   d Z ddlZddlZddlmZ ddlmZ ddlmZ 	 ddl	Z
n/# e$ r' 	 ddlZ
n# e$ r 	 ddl
Z
n# e$ r dZ
Y nw xY wY nw xY wY nw xY wd Zd Zd Zd	 Zd
 Zd Z ed          	 	 	 	 	 	 	 	 	 dd            Z ed          	 	 	 	 	 	 	 	 	 dd            ZdS )z)Utilities related to model visualization.    N)tree)keras_export)io_utilsc                      t           duS )z#Returns True if PyDot is available.N)pydot     `/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/utils/model_visualization.pycheck_pydotr      s    r	   c                      t                      sdS 	 t          j                            t          j                               dS # t          t          j        f$ r Y dS w xY w)z6Returns True if both PyDot and Graphviz are available.FT)r   r   DotcreateOSErrorInvocationExceptionr   r	   r
   check_graphvizr      se    == u 		%%%tU./   uus   0A AAc                     |                      ||          sBt          j        ||          }|                    dd           |                     |           d S d S )Npenwidth2)get_edger   Edgesetadd_edge)dotsrcdstedges       r
   r   r   +   s_    <<S!! z#s##S!!!T r	   c                     t          | j        d          r| j        j        }n6t          | j        d          r| j        j        }nt	          | j                  }|S )Nname__name__)hasattr
activationr   r   str)layeractivation_names     r
   get_layer_activation_namer%   2   s\    u(( 0*/	!:	.	. 0*3e.//r	   c                    | j         j        }|                    d          }|                    d          }|                    d          }|                    d          }|                    d          }|rt          d|           d}t	          d ||fD                       }	|r|	d	z  }	t          d
|	          }
|r|d|
 d| j         d| dz  }n|d|
 d| dz  }|r0t          | d          r | j        |d|
 dt          |            dz  }g }|rd }d }	 t          j        d | j                  }t          j        d | j                  }n# t          t          f$ r Y nw xY w|dk    r|                    d|pd d           |                    d|pd d           |rQd }	 t          j        d | j                  }n# t          t          f$ r Y nw xY w|                    d|pd d           |rIt          | d          r9| j        r2| j        r|                    d           n|                    d           |rt%          |          }
nd
}
|r|dd                     |          z   d!z   z  }|d"z  }|S )#Nshow_layer_namesshow_layer_activations
show_dtypeshow_shapesshow_trainablezInvalid kwargs: zC<<table border="0" cellborder="1" bgcolor="black" cellpadding="10">c              3   4   K   | ]}t          |          V  d S N)int).0xs     r
   	<genexpr>z#make_layer_label.<locals>.<genexpr>K   s(      CCc!ffCCCCCCr	         z<tr><td colspan="z9" bgcolor="black"><font point-size="16" color="white"><b>z</b> (z)</font></td></tr>z</b></font></td></tr>r!   z!<tr><td bgcolor="white" colspan="z'"><font point-size="14">Activation: <b>c                     | j         S r-   shaper0   s    r
   <lambda>z"make_layer_label.<locals>.<lambda>o   s    qw r	   c                     | j         S r-   r5   r7   s    r
   r8   z"make_layer_label.<locals>.<lambda>p   s     r	   
InputLayerz:<td bgcolor="white"><font point-size="14">Input shape: <b>?z</b></font></td>z;<td bgcolor="white"><font point-size="14">Output shape: <b>c                     | j         S r-   )dtyper7   s    r
   r8   z"make_layer_label.<locals>.<lambda>   s     r	   z;<td bgcolor="white"><font point-size="14">Output dtype: <b>	trainablezZ<td bgcolor="forestgreen"><font point-size="14" color="white"><b>Trainable</b></font></td>z\<td bgcolor="firebrick"><font point-size="14" color="white"><b>Non-trainable</b></font></td>z<tr> z</tr>z	</table>>)	__class__r   pop
ValueErrorsummaxr   r    r!   r%   r   map_structureinputoutputAttributeErrorappendweightsr>   lenjoin)r#   kwargs
class_namer'   r(   r)   r*   r+   tablecolspan_maxcolspancolsinput_shapeoutput_shaper=   s                  r
   make_layer_labelrU   <   s   )Jzz"455#ZZ(@AAL))J**]++KZZ 011N 64F44555 	N 
 CCz>&BCCCCCK q![!!G 
     *   $.     	
 	          	
 	

E<((

 (     7>>     	
 D 
	,->->LLK-.?.?NNLLN+ 	 	 	D	%%KK#'2'9c# # #   	$0$7C  	
 	
 	
  
	&'8'8%,GGEEN+ 	 	 	D	$)LS  	
 	
 	
  '%55 %- ? 	KK3    KK7    d)) 2"''$--''11	[ELs$   6E E'&E'+G GGc                     t          j        t          t          |                     t	          | fi |          }|                    dd           |                    dd           |                    dd           |S )N)labelfontname	Helveticaborder0margin)r   Noder"   idrU   r   )r#   rM   nodes      r
   	make_noder`      st    :c"U))nn,<U,M,Mf,M,MNNNDHHZ%%%HHXsHHXsKr	   zkeras.utils.model_to_dotFTTB   c
                 
   ddl m} | j        st          d          ddlm} ddlm} t                      st          d          |rMt          j
        d| j                  }|                    d	| j                   |                    d
d           nt          j                    }|                    d|           |                    dd           |                    d|           |                    dd           |                    d           |
                    dd          t          d          |
rt          d|
           |||||	d}
t!          | |j                  r| j        }n@t!          | |j                  s$t)          | fi |
}|                    |           |S | j        }i }i }t/          |          D ]\  }}|rwt!          ||j                  rbt1          ||||||d||		  	        }|                                }|d         ||j        <   |d         ||j        <   |                    |           ~t)          |fi |
}|                    |           t!          | |j                  r|t7          t9          |          dz
            D ]Z}t;          t=          ||                             }t;          t=          ||dz                                }t?          |||           [|S t/          |          D ] \  }}t;          t=          |                    }t/          |j                   D ]\  }} |||          }|| j!        v r|j"        D ]}|j#        }t;          t=          |                    }|s@|$                    |          sJ |$                    |          sJ t?          |||           ht!          ||j                  st!          ||j                  s@|$                    |          sJ |$                    |          sJ t?          |||           t!          ||j                  r.t?          ||||j                 %                                           t!          ||j                  rw||j                 %                                }t!          ||j                  r2||j                 %                                }t?          |||           t?          |||           ʐ|S )a  Convert a Keras model to dot format.

    Args:
        model: A Keras model instance.
        show_shapes: whether to display shape information.
        show_dtype: whether to display layer dtypes.
        show_layer_names: whether to display layer names.
        rankdir: `rankdir` argument passed to PyDot,
            a string specifying the format of the plot: `"TB"`
            creates a vertical plot; `"LR"` creates a horizontal plot.
        expand_nested: whether to expand nested Functional models
            into clusters.
        dpi: Image resolution in dots per inch.
        subgraph: whether to return a `pydot.Cluster` instance.
        show_layer_activations: Display layer activations (only for layers that
            have an `activation` property).
        show_trainable: whether to display if a layer is trainable.

    Returns:
        A `pydot.Dot` instance representing the Keras model or
        a `pydot.Cluster` instance representing nested model if
        `subgraph=True`.
    r   )make_node_keyyThis model has not yet been built. Build the model first by calling `build()` or by calling the model on a batch of data.)
functional)
sequentialzFYou must install pydot (`pip install pydot`) for model_to_dot to work.dashed)style
graph_namerW   	labeljustlrankdirconcentrateTdpisplinesorthorecordr5   layer_rangeN.Argument `layer_range` is no longer supported. Unrecognized keyword arguments: )r'   r(   r)   r*   r+   )subgraphr(   r+   r3   )&keras.src.ops.functionrd   builtrB   keras.src.modelsrf   rg   r   ImportErrorr   Clusterr   r   r   set_node_defaultsrA   
isinstance
Sequentiallayers
Functionalr`   add_node_operations	enumeratemodel_to_dot	get_nodesadd_subgraphrangerK   r"   r^   r   _inbound_nodes_nodesparent_nodes	operationget_nodeget_name)modelr*   r)   r'   rm   expand_nestedro   rv   r(   r+   rM   rd   rf   rg   r   r   r_   sub_n_first_nodesub_n_last_nodeir#   submodelsub_n_nodesinbound_layer_idlayer_idnode_keyparent_nodeinbound_layerr   output_names                                 r
   r   r      s   J 544444; 
,
 
 	
 ,+++++++++++ == 
$
 
 	

  
.m(uzBBB$$$S!!!!ikk	7###t$$$s	7###H---zz-&&2IJJJ FDFDDEEE -"8 "( F %.// #z455 #))&))T
" Of%%  5 	Zz/DEE 	# '=-
 
 
H #,,..K+6q>UZ(*5b/OEJ'X&&&& U--f--DLL %.// s6{{Q'' 	6 	6A"2fQi==112fQUm,,--HS*H5555
 f%% &> &>5r%yy>> !566 $	> $	>GAt$}UA..H5<''#'#4 !> !>K$/$9M'*2m+<+<'='=$( >"||,<====="||H55555 &6AAAA  *-9NOO >#-eZ5J#K#K 
"'*||4D'E'E E E E'*||H'='= = = = (.> I I I I!+E:3H!I!I " ($'$4$4UZ$@$I$I$K$K!" !" !" (z7LMM 
>#2 - 2$&hjj !  *%1FGG >.>$)J/""*(** !, !)dK @ @ @ @ (dH = = =I$	>J Jr	   zkeras.utils.plot_model	model.pngc
                    | j         st          d          t                      s5d}dt          j        v rt          j        |           dS t          |          t                      s5d}dt          j        v rt          j        |           dS t          |          |
	                    dd          t          d          |
rt          d|
           t          | ||||||||			  	        }t          |          }|dS t          j                            |          \  }}|sd
}n
|dd         }|                    ||           |dk    r.	 ddlm} |                    |          S # t          $ r Y dS w xY wdS )a  Converts a Keras model to dot format and save to a file.

    Example:

    ```python
    inputs = ...
    outputs = ...
    model = keras.Model(inputs=inputs, outputs=outputs)

    dot_img_file = '/tmp/model_1.png'
    keras.utils.plot_model(model, to_file=dot_img_file, show_shapes=True)
    ```

    Args:
        model: A Keras model instance
        to_file: File name of the plot image.
        show_shapes: whether to display shape information.
        show_dtype: whether to display layer dtypes.
        show_layer_names: whether to display layer names.
        rankdir: `rankdir` argument passed to PyDot,
            a string specifying the format of the plot: `"TB"`
            creates a vertical plot; `"LR"` creates a horizontal plot.
        expand_nested: whether to expand nested Functional models
            into clusters.
        dpi: Image resolution in dots per inch.
        show_layer_activations: Display layer activations (only for layers that
            have an `activation` property).
        show_trainable: whether to display if a layer is trainable.

    Returns:
        A Jupyter notebook Image object if Jupyter is installed.
        This enables in-line display of the model plots in notebooks.
    re   zFYou must install pydot (`pip install pydot`) for `plot_model` to work.zIPython.core.magics.namespaceNznYou must install graphviz (see instructions at https://graphviz.gitlab.io/download/) for `plot_model` to work.rs   rt   ru   )r*   r)   r'   rm   r   ro   r(   r+   pngr3   )formatpdfr   )display)filename)ry   rB   r   sysmodulesr   	print_msgr{   r   rA   r   r"   ospathsplitextwriteIPythonr   Image)r   to_filer*   r)   r'   rm   r   ro   r(   r+   rM   messager   _	extensionr   s                   r
   
plot_modelr   ^  s   ` ; 
,
 
 	

 == '( 	 +ck99 w'''Fg&&& '( 	
 +ck99 w'''Fg&&&zz-&&2IJJJ FDFDDEEE
)#5%
 
 
C 'llG
{7##G,,LAy "		abbM	IIgiI((( E	''''''=='=222 	 	 	DD	 s   E, ,
E:9E:)	FFTra   Frb   FFF)	r   FFFra   Frb   FF)__doc__r   r   	keras.srcr   keras.src.api_exportr   keras.src.utilsr   pydot_ngr   r{   	pydotplusr   r   r   r%   rU   r`   r   r   r   r	   r
   <module>r      s   / / 				 



       - - - - - - $ $ $ $ $ $ 	 	 	!!!!!   	LLLL 	 	 	EEE				  

 
 
    l l l^   ())  g g g *)gT &''  r r r ('r r rsO   # A.AA	9A	A A	AA	AA		AA