


import itertools
from dataclasses import dataclass
from typing import Optional

import pandas as pd
import pyarrow as pa

import datasets
from datasets.table import table_cast






@dataclass
class       _UpperCamelCase    (					datasets.BuilderConfig				):

				"""simple docstring"""







				lowerCAmelCase 		= None






class       _UpperCamelCase    (					datasets.ArrowBasedBuilder				):

				"""simple docstring"""







				lowerCAmelCase 		= PandasConfig

				def      _UpperCAmelCase					(						self   )	->				int:
					return datasets.DatasetInfo(features=self.config.features   )

				def      _UpperCAmelCase					(						self				,   a__   )	->				Tuple:
					if not self.config.data_files:
						raise ValueError(f'At least one data file must be specified, but got data_files={self.config.data_files}'   )
					A								=				dl_manager.download_and_extract(self.config.data_files   )
					if isinstance(a__				,   (str, list, tuple)   ):
						A								=				data_files
						if isinstance(a__				,   a__   ):
							A								=				[files]
						# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
						A								=				[dl_manager.iter_files(a__   ) for file in files]
						return [datasets.SplitGenerator(name=datasets.Split.TRAIN				,   gen_kwargs={"""files""": files}   )]
					A								=				[]
					for split_name, files in data_files.items():
						if isinstance(a__				,   a__   ):
							A								=				[files]
						# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
						A								=				[dl_manager.iter_files(a__   ) for file in files]
						splits.append(datasets.SplitGenerator(name=a__				,   gen_kwargs={"""files""": files}   )   )
					return splits

				def      _UpperCAmelCase					(						self				,   a__   )	->				pa.Table:
					if self.config.features is not None:
						# more expensive cast to support nested features with keys in a different order
						# allows str <-> int/float or str to Audio for example
						A								=				table_cast(a__				,   self.config.features.arrow_schema   )
					return pa_table

				def      _UpperCAmelCase					(						self				,   a__   )	->				List[Any]:
					for i, file in enumerate(itertools.chain.from_iterable(a__   )   ):
						with open(a__				,   """rb"""   ) as f:
							A								=				pa.Table.from_pandas(pd.read_pickle(a__   )   )
							yield i, self._cast_table(a__   )







import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import CONFIG_MAPPING


_lowercase       :      int	=	logging.get_logger(__name__)






class       _UpperCamelCase    (					__snake_case				):

				"""simple docstring"""







				lowerCAmelCase 		= 'upernet'

				def __init__(						self				,   a__=None				,   a__=512				,   a__=0.02				,   a__=[1, 2, 3, 6]				,   a__=True				,   a__=0.4				,   a__=384				,   a__=256				,   a__=1				,   a__=False				,   a__=255				,   **a__				,   )	->				Tuple:
					super().__init__(**a__   )

					if backbone_config is None:
						logger.info("""`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."""   )
						A								=				CONFIG_MAPPING["""resnet"""](out_features=["""stage1""", """stage2""", """stage3""", """stage4"""]   )
					elif isinstance(a__				,   a__   ):
						A								=				backbone_config.get("""model_type"""   )
						A								=				CONFIG_MAPPING[backbone_model_type]
						A								=				config_class.from_dict(a__   )

					A								=				backbone_config
					A								=				hidden_size
					A								=				initializer_range
					A								=				pool_scales
					A								=				use_auxiliary_head
					A								=				auxiliary_loss_weight
					A								=				auxiliary_in_channels
					A								=				auxiliary_channels
					A								=				auxiliary_num_convs
					A								=				auxiliary_concat_input
					A								=				loss_ignore_index

				def      _UpperCAmelCase					(						self   )	->				Dict:
					A								=				copy.deepcopy(self.__dict__   )
					A								=				self.backbone_config.to_dict()
					A								=				self.__class__.model_type
					return output



