

'''simple docstring'''







from __future__ import annotations

from PIL import Image

# Define glider example
__lowerCamelCase									=     [
    [0, 1, 0, 0, 0, 0, 0, 0],
    [0, 0, 1, 0, 0, 0, 0, 0],
    [1, 1, 1, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
]

# Define blinker example
__lowerCamelCase									=     [[0, 1, 0], [0, 1, 0], [0, 1, 0]]
def    UpperCAmelCase__     (   UpperCAmelCase__					)      ->      list[list[int]]:
       A_						       =   []
       for i in range(len(UpperCAmelCase__					)					):
              A_						       =   []
              for j in range(len(cells[i]					)					):
                     # Get the number of live neighbours
                     A_						       =   0
                     if i > 0 and j > 0:
                            neighbour_count += cells[i - 1][j - 1]
                     if i > 0:
                            neighbour_count += cells[i - 1][j]
                     if i > 0 and j < len(cells[i]					) - 1:
                            neighbour_count += cells[i - 1][j + 1]
                     if j > 0:
                            neighbour_count += cells[i][j - 1]
                     if j < len(cells[i]					) - 1:
                            neighbour_count += cells[i][j + 1]
                     if i < len(UpperCAmelCase__					) - 1 and j > 0:
                            neighbour_count += cells[i + 1][j - 1]
                     if i < len(UpperCAmelCase__					) - 1:
                            neighbour_count += cells[i + 1][j]
                     if i < len(UpperCAmelCase__					) - 1 and j < len(cells[i]					) - 1:
                            neighbour_count += cells[i + 1][j + 1]

                     # Rules of the game of life (excerpt from Wikipedia):
                     # 1. Any live cell with two or three live neighbours survives.
                     # 2. Any dead cell with three live neighbours becomes a live cell.
                     # 3. All other live cells die in the next generation.
                     #    Similarly, all other dead cells stay dead.
                     A_						       =   cells[i][j] == 1
                     if (
                         (alive and 2 <= neighbour_count <= 3)
                         or not alive
                         and neighbour_count == 3
                     ):
                            next_generation_row.append(1					)
                     else:
                            next_generation_row.append(0					)

              next_generation.append(UpperCAmelCase__					)
       return next_generation
def    UpperCAmelCase__     (   UpperCAmelCase__,							UpperCAmelCase__					)      ->      list[Image.Image]:
       A_						       =   []
       for _ in range(UpperCAmelCase__					):
              # Create output image
              A_						       =   Image.new("""RGB""",							(len(cells[0]					), len(UpperCAmelCase__					))					)
              A_						       =   img.load()

              # Save cells to image
              for x in range(len(UpperCAmelCase__					)					):
                     for y in range(len(cells[0]					)					):
                            A_						       =   2_55 - cells[y][x] * 2_55
                            A_						       =   (colour, colour, colour)

        # Save image
              images.append(UpperCAmelCase__					)
              A_						       =   new_generation(UpperCAmelCase__					)
       return images


if __name__ == "__main__":
      __lowerCamelCase									=     generate_images(GLIDER, 16)
      images[0].save('''out.gif''', save_all=True, append_images=images[1:])



'''simple docstring'''







from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


__lowerCamelCase									=     logging.get_logger(__name__)

__lowerCamelCase									=     {
    '''microsoft/resnet-50''': '''https://huggingface.co/microsoft/resnet-50/blob/main/config.json''',
}


class        A__   (   _snake_case    ,    _snake_case      ):
    lowercase						       =		"resnet"
    lowercase						       =		["basic", "bottleneck"]



    def __init__(       self		,					UpperCamelCase__=3		,					UpperCamelCase__=64		,					UpperCamelCase__=[256, 512, 1024, 2048]		,					UpperCamelCase__=[3, 4, 6, 3]		,					UpperCamelCase__="bottleneck"		,					UpperCamelCase__="relu"		,					UpperCamelCase__=False		,					UpperCamelCase__=None		,					UpperCamelCase__=None		,					**UpperCamelCase__		,					)    ->   List[str]:





           '''simple docstring'''
           super().__init__(**UpperCamelCase__							)
           if layer_type not in self.layer_types:
                  raise ValueError(f'''layer_type={layer_type} is not one of {",".join(self.layer_types							)}'''							)
           A_						       =   num_channels
           A_						       =   embedding_size
           A_						       =   hidden_sizes
           A_						       =   depths
           A_						       =   layer_type
           A_						       =   hidden_act
           A_						       =   downsample_in_first_stage
           A_						       =   ["""stem"""] + [f'''stage{idx}''' for idx in range(1		,					len(UpperCamelCase__							) + 1							)]
           A_       ,      A_						       =   get_aligned_output_features_output_indices(
               out_features=UpperCamelCase__		,					out_indices=UpperCamelCase__		,					stage_names=self.stage_names							)


class        A__   (   _snake_case      ):
    lowercase						       =		version.parse("1.11"      )



    @property
    def        snake_case_      (       self							)    ->   Mapping[str, Mapping[int, str]]:





           '''simple docstring'''
           return OrderedDict(
               [
                   ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
               ]							)







    @property
    def        snake_case_      (       self							)    ->   float:





           '''simple docstring'''
           return 1e-3
