
    sgn                     L   d dl mZ d dlmZmZ d dlmZ d dlZd dl	m
Z d dlmZmZmZ d dlmZmZ d dlmZ d dlmZmZmZmZ d dlmZmZmZmZ d d	lm Z m!Z! d
Z"dZ# G d dejH                        Z% G d dejH                        Z& G d dejH                        Z' G d dejH                        Z( G d dejH                        Z) G d dejH                        Z* G d dejH                        Z+ G d dejH                        Z, G d dejH                        Z- G d dejH                        Z. G d  d!ejH                        Z/ G d" d#ejH                        Z0 G d$ d%ejH                        Z1 G d& d'ejH                        Z2 G d( d)e      Z3 G d* d+ejH                        Z4 e d,e"       G d- d.e3             Z5d/Z6 ee5e6        ee5ee0        G d1 d2ejH                        Z7 G d3 d4ejH                        Z8 e d5e"       G d6 d7e3             Z9d8Z: ee9e:        ee9ee0       y)9    )partial)OptionalTupleN)
FrozenDictfreezeunfreeze)flatten_dictunflatten_dict)RegNetConfig)"FlaxBaseModelOutputWithNoAttentionFlaxBaseModelOutputWithPooling,FlaxBaseModelOutputWithPoolingAndNoAttention(FlaxImageClassifierOutputWithNoAttention)ACT2FNFlaxPreTrainedModel append_replace_return_docstringsoverwrite_call_docstring)add_start_docstrings%add_start_docstrings_to_model_forwarda  

    This model inherits from [`FlaxPreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading, saving and converting weights from PyTorch models)

    This model is also a
    [flax.linen.Module](https://flax.readthedocs.io/en/latest/api_reference/flax.linen/module.html) subclass. Use it as
    a regular Flax linen Module and refer to the Flax documentation for all matter related to general usage and
    behavior.

    Finally, this model supports inherent JAX features such as:

    - [Just-In-Time (JIT) compilation](https://jax.readthedocs.io/en/latest/jax.html#just-in-time-compilation-jit)
    - [Automatic Differentiation](https://jax.readthedocs.io/en/latest/jax.html#automatic-differentiation)
    - [Vectorization](https://jax.readthedocs.io/en/latest/jax.html#vectorization-vmap)
    - [Parallelization](https://jax.readthedocs.io/en/latest/jax.html#parallelization-pmap)

    Parameters:
        config ([`RegNetConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~FlaxPreTrainedModel.from_pretrained`] method to load the model weights.
        dtype (`jax.numpy.dtype`, *optional*, defaults to `jax.numpy.float32`):
            The data type of the computation. Can be one of `jax.numpy.float32`, `jax.numpy.float16` (on GPUs) and
            `jax.numpy.bfloat16` (on TPUs).

            This can be used to enable mixed-precision training or half-precision inference on GPUs or TPUs. If
            specified all the computation will be performed with the given `dtype`.

            **Note that this only specifies the dtype of the computation and does not influence the dtype of model
            parameters.**

            If you wish to change the dtype of the model parameters, see [`~FlaxPreTrainedModel.to_fp16`] and
            [`~FlaxPreTrainedModel.to_bf16`].
a@  
    Args:
        pixel_values (`numpy.ndarray` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See
            [`RegNetImageProcessor.__call__`] for details.

        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
c                   4    e Zd ZdZej
                  d        Zy)IdentityzIdentity function.c                     |S N )selfxkwargss      b/var/www/html/venv/lib/python3.12/site-packages/transformers/models/regnet/modeling_flax_regnet.py__call__zIdentity.__call__b   s        N)__name__
__module____qualname____doc__nncompactr   r   r    r   r   r   _   s    ZZ r    r   c                       e Zd ZU eed<   dZeed<   dZeed<   dZeed<   dZe	e
   ed<   ej                  Zej                  ed	<   d
 Zddej                  dedej                  fdZy)FlaxRegNetConvLayerout_channels   kernel_size   stridegroupsrelu
activationdtypec                    t        j                  | j                  | j                  | j                  f| j                  | j                  dz  | j
                  dt         j                  j                  ddd      | j                        | _	        t        j                  dd	| j                  
      | _        | j                  t        | j                     | _        y t               | _        y )N   F       @fan_outtruncated_normalmodedistribution)r+   stridespaddingfeature_group_countuse_biaskernel_initr1   ?h㈵>momentumepsilonr1   )r%   Convr)   r+   r-   r.   initializersvariance_scalingr1   convolution	BatchNormnormalizationr0   r   r   activation_funcr   s    r   setupzFlaxRegNetConvLayer.setupo   s    77))4+;+;<KK$$) $889[m8n**	
  \\3TZZX:>//:Uvdoo6[c[er    hidden_statedeterministicreturnc                 p    | j                  |      }| j                  ||      }| j                  |      }|S N)use_running_average)rG   rI   rJ   )r   rM   rN   s      r   r   zFlaxRegNetConvLayer.__call__}   s=    ''5)),M)Z++L9r    NT)r!   r"   r#   int__annotations__r+   r-   r.   r0   r   strjnpfloat32r1   rL   ndarrayboolr   r   r    r   r(   r(   g   so    KFCOFCO &J&{{E399"fS[[  QTQ\Q\ r    r(   c                       e Zd ZU eed<   ej                  Zej                  ed<   d Zd	dej                  de
dej                  fdZy)
FlaxRegNetEmbeddingsconfigr1   c                     t        | j                  j                  dd| j                  j                  | j                        | _        y )Nr*   r3   )r+   r-   r0   r1   )r(   r]   embedding_size
hidden_actr1   embedderrK   s    r   rL   zFlaxRegNetEmbeddings.setup   s5    +KK&&{{--**
r    pixel_valuesrN   rO   c                     |j                   d   }|| j                  j                  k7  rt        d      | j	                  ||      }|S )NzeMake sure that the channel dimension of the pixel values match with the one set in the configuration.rN   )shaper]   num_channels
ValueErrorra   )r   rb   rN   rg   rM   s        r   r   zFlaxRegNetEmbeddings.__call__   sN    #))"-4;;333w  }}\}Or    NrS   )r!   r"   r#   r   rU   rW   rX   r1   rL   rY   rZ   r   r   r    r   r\   r\      sD    {{E399"
S[[  QTQ\Q\ r    r\   c                       e Zd ZU dZeed<   dZeed<   ej                  Z	ej                  ed<   d Z
ddej                  ded	ej                  fd
Zy)FlaxRegNetShortCutz
    RegNet shortcut, used to project the residual features to the correct size. If needed, it is also used to
    downsample the input using `stride=2`.
    r)   r3   r-   r1   c                    t        j                  | j                  d| j                  dt         j                  j                  ddd      | j                        | _        t        j                  dd	| j                  
      | _	        y )Nr,   r,   Fr4   r5   r6   r7   )r+   r:   r=   r>   r1   r?   r@   rA   )
r%   rD   r)   r-   rE   rF   r1   rG   rH   rI   rK   s    r   rL   zFlaxRegNetShortCut.setup   se    77KK889[m8n**
  \\3TZZXr    r   rN   rO   c                 N    | j                  |      }| j                  ||      }|S rQ   )rG   rI   )r   r   rN   rM   s       r   r   zFlaxRegNetShortCut.__call__   s-    ''*)),M)Zr    NrS   )r!   r"   r#   r$   rT   rU   r-   rW   rX   r1   rL   rY   rZ   r   r   r    r   rj   rj      sR    
 FCO{{E399"	Y#++ d ckk r    rj   c                       e Zd ZU eed<   eed<   ej                  Zej                  ed<   d Zdej                  dej                  fdZ
y)	FlaxRegNetSELayerCollectionin_channelsreduced_channelsr1   c           	      P   t        j                  | j                  dt         j                  j	                  ddd      | j
                  d      | _        t        j                  | j                  dt         j                  j	                  ddd      | j
                  d      | _        y )	Nrl   r4   r5   r6   r7   0)r+   r>   r1   name2)	r%   rD   rq   rE   rF   r1   conv_1rp   conv_2rK   s    r   rL   z!FlaxRegNetSELayerCollection.setup   s    gg!!889[m8n**
 gg889[m8n**
r    rM   rO   c                     | j                  |      }t        j                  |      }| j                  |      }t        j                  |      }|S r   )rv   r%   r/   rw   sigmoid)r   rM   	attentions      r   r   z$FlaxRegNetSELayerCollection.__call__   s@    {{<0ww|,{{<0JJ|,	r    N)r!   r"   r#   rT   rU   rW   rX   r1   rL   rY   r   r   r    r   ro   ro      s@    {{E399"
 S[[ S[[ r    ro   c                       e Zd ZU dZeed<   eed<   ej                  Zej                  ed<   d Z	dej                  dej                  fdZy	)
FlaxRegNetSELayerz|
    Squeeze and Excitation layer (SE) proposed in [Squeeze-and-Excitation Networks](https://arxiv.org/abs/1709.01507).
    rp   rq   r1   c                     t        t        j                  d      | _        t	        | j
                  | j                  | j                        | _        y )Nr   r   r   r;   r1   )	r   r%   avg_poolpoolerro   rp   rq   r1   rz   rK   s    r   rL   zFlaxRegNetSELayer.setup   s8    bkk3CD4T5E5EtG\G\dhdndnor    rM   rO   c                     | j                  ||j                  d   |j                  d   f|j                  d   |j                  d   f      }| j                  |      }||z  }|S )Nr,   r3   window_shaper:   )r   rf   rz   )r   rM   pooledrz   s       r   r   zFlaxRegNetSELayer.__call__   st    &,,Q/1C1CA1FG!''*L,>,>q,AB  

 NN6*	#i/r    N)r!   r"   r#   r$   rT   rU   rW   rX   r1   rL   rY   r   r   r    r   r|   r|      sH     {{E399"pS[[ S[[ r    r|   c                       e Zd ZU eed<   eed<   dZeed<   ej                  Z	ej                  ed<   d Z
ddej                  ded	ej                  fd
Zy)FlaxRegNetXLayerCollectionr]   r)   r,   r-   r1   c           	         t        d| j                  | j                  j                  z        }t	        | j                  d| j                  j
                  | j                  d      t	        | j                  | j                  || j                  j
                  | j                  d      t	        | j                  dd | j                  d      g| _        y )Nr,   rs   r+   r0   r1   rt   1r-   r.   r0   r1   rt   ru   )	maxr)   r]   groups_widthr(   r`   r1   r-   layerr   r.   s     r   rL   z FlaxRegNetXLayerCollection.setup   s    Q))T[[-E-EEF  !!;;11jj  !!{{;;11jj  !!jj!

r    rM   rN   rO   c                 <    | j                   D ]  } |||      } |S Nre   r   )r   rM   rN   r   s       r   r   z#FlaxRegNetXLayerCollection.__call__  s)    ZZ 	LE ]KL	Lr    NrS   )r!   r"   r#   r   rU   rT   r-   rW   rX   r1   rL   rY   rZ   r   r   r    r   r   r      sS    FCO{{E399"
8S[[  QTQ\Q\ r    r   c                       e Zd ZU dZeed<   eed<   eed<   dZeed<   ej                  Z
ej                  ed<   d Zdd	ej                  d
edej                  fdZy)FlaxRegNetXLayerzt
    RegNet's layer composed by three `3x3` convolutions, same as a ResNet bottleneck layer with reduction = 1.
    r]   rp   r)   r,   r-   r1   c                    | j                   | j                  k7  xs | j                  dk7  }|r,t        | j                  | j                  | j                        n	t               | _        t        | j                  | j                   | j                  | j                  | j                        | _	        t        | j                  j                     | _        y Nr,   )r-   r1   )rp   r)   r-   r1   )rp   r)   r-   rj   r1   r   shortcutr   r]   r   r   r`   rJ   r   should_apply_shortcuts     r   rL   zFlaxRegNetXLayer.setup   s     $ 0 0D4E4E E YXYIY % !!{{jj  	 0KK((**;;**

  &dkk&<&<=r    rM   rN   rO   c                 ~    |}| j                  |      }| j                  ||      }||z  }| j                  |      }|S r   r   r   rJ   r   rM   rN   residuals       r   r   zFlaxRegNetXLayer.__call__4  G    zz,/===G ++L9r    NrS   r!   r"   r#   r$   r   rU   rT   r-   rW   rX   r1   rL   rY   rZ   r   r   r    r   r   r     s`     FCO{{E399">(S[[  QTQ\Q\ r    r   c                       e Zd ZU eed<   eed<   eed<   dZeed<   ej                  Z	ej                  ed<   d Z
dej                  d	ej                  fd
Zy)FlaxRegNetYLayerCollectionr]   rp   r)   r,   r-   r1   c                 &   t        d| j                  | j                  j                  z        }t	        | j                  d| j                  j
                  | j                  d      t	        | j                  | j                  || j                  j
                  | j                  d      t        | j                  t        t        | j                  dz              | j                  d      t	        | j                  dd | j                  d	      g| _        y )
Nr,   rs   r   r   r      ru   )rq   r1   rt   3)r   r)   r]   r   r(   r`   r1   r-   r|   rT   roundrp   r   r   s     r   rL   z FlaxRegNetYLayerCollection.setupD  s    Q))T[[-E-EEF  !!;;11jj  !!{{;;11jj !!!$U4+;+;a+?%@!Ajj	  !!jj-

r    rM   rO   c                 8    | j                   D ]
  } ||      } |S r   r   )r   rM   r   s      r   r   z#FlaxRegNetYLayerCollection.__call__f  s%    ZZ 	/E .L	/r    N)r!   r"   r#   r   rU   rT   r-   rW   rX   r1   rL   rY   r   r   r    r   r   r   =  sP    FCO{{E399" 
DS[[ S[[ r    r   c                       e Zd ZU dZeed<   eed<   eed<   dZeed<   ej                  Z
ej                  ed<   d Zdd	ej                  d
edej                  fdZy)FlaxRegNetYLayerzC
    RegNet's Y layer: an X layer with Squeeze and Excitation.
    r]   rp   r)   r,   r-   r1   c                    | j                   | j                  k7  xs | j                  dk7  }|r,t        | j                  | j                  | j                        n	t               | _        t        | j                  | j                   | j                  | j                  | j                        | _	        t        | j                  j                     | _        y r   )rp   r)   r-   rj   r1   r   r   r   r]   r   r   r`   rJ   r   s     r   rL   zFlaxRegNetYLayer.setupw  s     $ 0 0D4E4E E YXYIY % !!{{jj  	 0KK((**;;**

  &dkk&<&<=r    rM   rN   rO   c                 ~    |}| j                  |      }| j                  ||      }||z  }| j                  |      }|S r   r   r   s       r   r   zFlaxRegNetYLayer.__call__  r   r    NrS   r   r   r    r   r   r   l  s`     FCO{{E399">*S[[  QTQ\Q\ r    r   c                       e Zd ZU dZeed<   eed<   eed<   dZeed<   dZeed<   e	j                  Ze	j                  ed<   d	 Zdd
e	j                  dede	j                  fdZy)FlaxRegNetStageLayersCollection4
    A RegNet stage composed by stacked layers.
    r]   rp   r)   r3   r-   depthr1   c                    | j                   j                  dk(  rt        nt        } || j                   | j                  | j
                  | j                  | j                  d      g}t        | j                  dz
        D ]R  }|j                   || j                   | j
                  | j
                  | j                  t        |dz                      T || _        y )Nr   rs   )r-   r1   rt   r,   r1   rt   )r]   
layer_typer   r   rp   r)   r-   r1   ranger   appendrV   layers)r   r   r   is       r   rL   z%FlaxRegNetStageLayersCollection.setup  s    $(KK$:$:c$A GW   !!{{jj

 tzzA~& 		AMMKK%%%%**QU		 r    r   rN   rO   c                 @    |}| j                   D ]  } |||      } |S r   r   )r   r   rN   rM   r   s        r   r   z(FlaxRegNetStageLayersCollection.__call__  s.    [[ 	LE ]KL	Lr    NrS   r!   r"   r#   r$   r   rU   rT   r-   r   rW   rX   r1   rL   rY   rZ   r   r   r    r   r   r     sf     FCOE3N{{E399"8#++ d ckk r    r   c                       e Zd ZU dZeed<   eed<   eed<   dZeed<   dZeed<   e	j                  Ze	j                  ed<   d	 Zdd
e	j                  dede	j                  fdZy)FlaxRegNetStager   r]   rp   r)   r3   r-   r   r1   c                     t        | j                  | j                  | j                  | j                  | j
                  | j                        | _        y )N)rp   r)   r-   r   r1   )r   r]   rp   r)   r-   r   r1   r   rK   s    r   rL   zFlaxRegNetStage.setup  s<    5KK((**;;****
r    r   rN   rO   c                 (    | j                  ||      S r   r   )r   r   rN   s      r   r   zFlaxRegNetStage.__call__  s    {{1M{::r    NrS   r   r   r    r   r   r     sf     FCOE3N{{E399"
;#++ ;d ;ckk ;r    r   c            	           e Zd ZU eed<   ej                  Zej                  ed<   d Z	 	 d
dej                  de
de
defdZy	)FlaxRegNetStageCollectionr]   r1   c                 v   t        | j                  j                  | j                  j                  dd        }t        | j                  | j                  j                  | j                  j                  d   | j                  j
                  rdnd| j                  j                  d   | j                  d      g}t        t        || j                  j                  dd              D ]K  \  }\  \  }}}|j                  t        | j                  |||| j                  t        |dz                      M || _        y )Nr,   r   r3   rs   )r-   r   r1   rt   )r   r1   rt   )zipr]   hidden_sizesr   r_   downsample_in_first_stagedepthsr1   	enumerater   rV   stages)r   in_out_channelsr   r   rp   r)   r   s          r   rL   zFlaxRegNetStageCollection.setup  s   dkk668P8PQRQS8TU**((+ KKAAqqkk((+jj

 8A_VZVaVaVhVhijikVlAm7n 	3A3+lUMM[,e[_[e[elopqtupulvw	
 r    rM   output_hidden_statesrN   rO   c                     |rdnd }| j                   D ]&  }|r||j                  dddd      fz   } |||      }( ||fS )Nr   r   r*   r,   r3   re   )r   	transpose)r   rM   r   rN   hidden_statesstage_modules         r   r   z"FlaxRegNetStageCollection.__call__  s]     3 KK 	SL# -1G1G1aQR1S0U U'MRL		S ]**r    N)FTr!   r"   r#   r   rU   rW   rX   r1   rL   rY   rZ   r   r   r   r    r   r   r     sV    {{E399"0 &+"	+kk+ #+ 	+
 
,+r    r   c                       e Zd ZU eed<   ej                  Zej                  ed<   d Z	 	 	 ddej                  de
de
de
def
d	Zy
)FlaxRegNetEncoderr]   r1   c                 P    t        | j                  | j                        | _        y )Nr   )r   r]   r1   r   rK   s    r   rL   zFlaxRegNetEncoder.setup  s    /4::Nr    rM   r   return_dictrN   rO   c                     | j                  |||      \  }}|r||j                  dddd      fz   }|st        d ||fD              S t        ||      S )N)r   rN   r   r*   r,   r3   c              3   &   K   | ]	  }||  y wr   r   ).0vs     r   	<genexpr>z-FlaxRegNetEncoder.__call__.<locals>.<genexpr>!  s     SqQ]Ss   )last_hidden_stater   )r   r   tupler   )r   rM   r   r   rN   r   s         r   r   zFlaxRegNetEncoder.__call__  st     '+kk/CS` '2 '
#m  )\-C-CAq!Q-O,QQMS\=$ASSS1*'
 	
r    N)FTTr   r   r    r   r   r     sd    {{E399"O &+ "
kk
 #
 	

 
 
,
r    r   c                       e Zd ZU dZeZdZdZdZe	j                  ed<   ddej                  dfd	ed
edej                  def fdZddej&                  j(                  dededefdZ ee      	 	 	 	 ddededee   dee   fd       Z xZS )FlaxRegNetPreTrainedModelz
    An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
    models.
    regnetrb   Nmodule_class)r,      r   r*   r   Tr]   seedr1   _do_initc                      | j                   d||d|}|$d|j                  |j                  |j                  f}t        |   ||||||       y )Nr]   r1   r,   )input_shaper   r1   r   r   )r   
image_sizerg   super__init__)	r   r]   r   r   r1   r   r   module	__class__s	           r   r   z"FlaxRegNetPreTrainedModel.__init__5  sc     #""H&HHf//1B1BFDWDWXK[tSXcklr    rngr   paramsrO   c                 X   t        j                  || j                        }d|i}| j                  j	                  ||d      }|dt        t        |            }t        t        |            }| j                  D ]
  }||   ||<    t               | _        t        t        |            S |S )Nr   r   F)r   )rW   zerosr1   r   initr	   r   _missing_keyssetr   r
   )r   r   r   r   rb   rngsrandom_paramsmissing_keys           r   init_weightsz&FlaxRegNetPreTrainedModel.init_weightsC  s    yyDJJ?#((|(O(-)@AM!(6"23F#11 A&3K&@{#A!$D.011  r    trainr   r   c           	         ||n| j                   j                  }||n| j                   j                  }t        j                  |d      }i }| j
                  j                  ||d   n| j                  d   ||d   n| j                  d   dt        j                  |t        j                        | ||||rdg      S d      S )N)r   r3   r*   r,   r   batch_stats)r   r   r   F)r   mutable)
r]   r   r   rW   r   r   applyr   arrayrX   )r   rb   r   r   r   r   r   s          r   r   z"FlaxRegNetPreTrainedModel.__call__U  s     %9$D $++JjJj 	 &1%<k$++BYBY}}\<@ {{  .4.@&*dkkRZF[8>8Jvm4PTP[P[\iPj IIl#++6I ',]O ! 
 	
 38 ! 
 	
r    r   )NFNN)r!   r"   r#   r$   r   config_classbase_model_prefixmain_input_namer   r%   ModulerU   rW   rX   rT   r1   rZ   r   jaxrandomPRNGKeyr   r   r   r   REGNET_INPUTS_DOCSTRINGdictr   r   __classcell__)r   s   @r   r   r   *  s    
  L $O"L"))"
 %;;mm 	m
 yym m!

 2 2 ! !PZ !fp !$ ++BC /3&*
 
 	

 'tn
 d^
 D
r    r   c            	       t    e Zd ZU eed<   ej                  Zej                  ed<   d Z	 	 	 d
de	de	de	de
fdZy	)FlaxRegNetModuler]   r1   c                     t        | j                  | j                        | _        t	        | j                  | j                        | _        t        t        j                  d      | _	        y )Nr   r~   r   )
r\   r]   r1   ra   r   encoderr   r%   r   r   rK   s    r   rL   zFlaxRegNetModule.setup{  sF    ,T[[

K(DJJG KK$
r    rN   r   r   rO   c                    ||n| j                   j                  }||n| j                   j                  }| j                  ||      }| j	                  ||||      }|d   }| j                  ||j                  d   |j                  d   f|j                  d   |j                  d   f      j                  dddd      }|j                  dddd      }|s
||f|dd  z   S t        |||j                        S )	Nre   )r   r   rN   r   r,   r3   r   r*   )r   pooler_outputr   )
r]   r   use_return_dictra   r  r   rf   r   r   r   )	r   rb   rN   r   r   embedding_outputencoder_outputsr   pooled_outputs	            r   r   zFlaxRegNetModule.__call__  s-    %9$D $++JjJj 	 &1%<k$++B]B]==]=S,,!5#'	 ' 
 ,A.+11!46G6M6Ma6PQ&,,Q/1B1H1H1KL $ 
 )Aq!Q
	 	 .771aC%}58KKK;/')77
 	
r    N)TFT)r!   r"   r#   r   rU   rW   rX   r1   rL   rZ   r   r   r   r    r   r  r  w  sW    {{E399"
 #%* &
 &
 #	&

 &
 
6&
r    r  zOThe bare RegNet model outputting raw features without any specific head on top.c                       e Zd ZeZy)FlaxRegNetModelN)r!   r"   r#   r  r   r   r    r   r  r    s	    
 $Lr    r  at  
    Returns:

    Examples:

    ```python
    >>> from transformers import AutoImageProcessor, FlaxRegNetModel
    >>> from PIL import Image
    >>> import requests

    >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
    >>> image = Image.open(requests.get(url, stream=True).raw)

    >>> image_processor = AutoImageProcessor.from_pretrained("facebook/regnet-y-040")
    >>> model = FlaxRegNetModel.from_pretrained("facebook/regnet-y-040")

    >>> inputs = image_processor(images=image, return_tensors="np")
    >>> outputs = model(**inputs)
    >>> last_hidden_states = outputs.last_hidden_state
    ```
)output_typer   c                       e Zd ZU eed<   ej                  Zej                  ed<   d Zdej                  dej                  fdZ
y)FlaxRegNetClassifierCollectionr]   r1   c                 z    t        j                  | j                  j                  | j                  d      | _        y )Nr   r   )r%   Denser]   
num_labelsr1   
classifierrK   s    r   rL   z$FlaxRegNetClassifierCollection.setup  s%    ((4;;#9#9RUVr    r   rO   c                 $    | j                  |      S r   )r  )r   r   s     r   r   z'FlaxRegNetClassifierCollection.__call__  s    q!!r    N)r!   r"   r#   r   rU   rW   rX   r1   rL   rY   r   r   r    r   r  r    s;    {{E399"W"#++ "#++ "r    r  c                   j    e Zd ZU eed<   ej                  Zej                  ed<   d Z	 	 	 	 dde	fdZ
y)&FlaxRegNetForImageClassificationModuler]   r1   c                     t        | j                  | j                        | _        | j                  j                  dkD  r't        | j                  | j                        | _        y t               | _        y )Nr   r   r   )r  r]   r1   r   r  r  r  r   rK   s    r   rL   z,FlaxRegNetForImageClassificationModule.setup  sL    &dkkL;;!!A%<T[[PTPZPZ[DO&jDOr    NrN   c                    ||n| j                   j                  }| j                  ||||      }|r|j                  n|d   }| j	                  |d d d d ddf         }|s|f|dd  z   }|S t        ||j                        S )N)rN   r   r   r,   r   r3   )logitsr   )r]   r
  r   r	  r  r   r   )	r   rb   rN   r   r   outputsr  r  outputs	            r   r   z/FlaxRegNetForImageClassificationModule.__call__  s     &1%<k$++B]B]++'!5#	  
 2=--'!*q!Qz!:;Y,FM7vU\UjUjkkr    )NTNN)r!   r"   r#   r   rU   rW   rX   r1   rL   rZ   r   r   r    r   r  r    s>    {{E399") "!l lr    r  z
    RegNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for
    ImageNet.
    c                       e Zd ZeZy) FlaxRegNetForImageClassificationN)r!   r"   r#   r  r   r   r    r   r   r     s	     :Lr    r   aa  
    Returns:

    Example:

    ```python
    >>> from transformers import AutoImageProcessor, FlaxRegNetForImageClassification
    >>> from PIL import Image
    >>> import jax
    >>> import requests

    >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
    >>> image = Image.open(requests.get(url, stream=True).raw)

    >>> image_processor = AutoImageProcessor.from_pretrained("facebook/regnet-y-040")
    >>> model = FlaxRegNetForImageClassification.from_pretrained("facebook/regnet-y-040")

    >>> inputs = image_processor(images=image, return_tensors="np")
    >>> outputs = model(**inputs)
    >>> logits = outputs.logits

    >>> # model predicts one of the 1000 ImageNet classes
    >>> predicted_class_idx = jax.numpy.argmax(logits, axis=-1)
    >>> print("Predicted class:", model.config.id2label[predicted_class_idx.item()])
    ```
);	functoolsr   typingr   r   
flax.linenlinenr%   r   	jax.numpynumpyrW   flax.core.frozen_dictr   r   r   flax.traverse_utilr	   r
   transformersr   "transformers.modeling_flax_outputsr   r   r   r    transformers.modeling_flax_utilsr   r   r   r   transformers.utilsr   r   REGNET_START_DOCSTRINGr  r   r   r(   r\   rj   ro   r|   r   r   r   r   r   r   r   r   r   r  r  FLAX_VISION_MODEL_DOCSTRINGr  r  r   FLAX_VISION_CLASSIF_DOCSTRINGr   r    r   <module>r0     s  "  "  
  > > ; %  ! F ryy ")) :299 0 6")) <		 0% %P%ryy %P, ,^&ryy &R,bii ,`;bii ;6'+		 '+V
		 
>I
 3 I
Z4
ryy 4
n U$/ $	$ , *E F  ."RYY "$lRYY $lN  :'@ ::! 6 9;X Y  $8r    