def generateParameters(cls, input_dict: Dict[str, Tuple[str, Dict[str, TypeShape], str]], expected_outputs: Set[TypeShape], variable_pool: dict = None) -> \ Tuple[List[Dict[str, object]], List[float]]: default_input_label, default_input_ntss, _ = input_dict.get(IOLabel.MERGE_IN) other_input_label, other_input_ntss, _ = input_dict.get(IOLabel.MERGE_OTHER) default_input_nts = default_input_ntss[default_input_label] other_input_nts = other_input_ntss[other_input_label] if default_input_nts.dtype != other_input_nts.dtype: return [], [] out_shape = Shape() for _dim in default_input_nts.shape.dim: if _dim.name == DimNames.CHANNEL or \ _dim.name == DimNames.UNITS: out_shape.dim.append(Shape.Dim(_dim.name, _dim.size + other_input_nts.shape[_dim.name])) elif _dim.size != other_input_nts.shape[_dim.name]: return [], [] else: out_shape.dim.append(Shape.Dim(_dim.name, _dim.size)) input_mapping = dict([(l_in, (l_out, df_id_name)) for l_in, (l_out, _, df_id_name) in input_dict.items()]) return [{cls.arg_INPUT_MAPPING: input_mapping, cls.arg_ATTRIBUTES: {cls.arg_OUT_NAMED_TYPE_SHAPES: {IOLabel.MERGE_OUT: TypeShape(default_input_nts.dtype, out_shape)}}, }], [1.0]
def __init__(self, **kwargs): super(SupervisedData, self).__init__(**kwargs) self.batch = kwargs.get(self.arg_BATCH) self._namedOutputShapes = kwargs.get(self.arg_SHAPES) for _shape in self._namedOutputShapes.values(): _shape.shape.dim.insert(0, Shape.Dim(Shape.Dim.Names.BATCH, self.batch)) self.train_X = kwargs.get(self.arg_TRAINX) self.train_Y = kwargs.get(self.arg_TRAINY) self.test_X = kwargs.get(self.arg_TESTX) self.test_Y = kwargs.get(self.arg_TESTY) self.valid_X = kwargs.get(self.arg_VALIDX) self.valid_Y = kwargs.get(self.arg_VALIDY) if self.train_X is None and self.test_X is None and self.valid_X is None: raise Exception('All input data is None!') if self.train_X is not None: dimension_sizes = next(iter(self.train_X)).shape elif self.test_X is not None: dimension_sizes = next(iter(self.test_X)).shape elif self.valid_X is not None: dimension_sizes = next(iter(self.valid_X)).shape if (self.train_X is not None and next(iter(self.train_X)).shape != dimension_sizes) or \ (self.test_X is not None and next(iter(self.test_X)).shape != dimension_sizes) or \ (self.valid_X is not None and next(iter(self.valid_X)).shape != dimension_sizes): raise Exception('Train test and valid data must have the same size!') self.idx = 0 self.len = 1 self.data_X = self.test_X self.data_Y = self.test_Y self.state = ''
def max_transform(cls, nts): if nts.dtype not in cls.allowedTypes: return None s = Shape() result = TypeShape(nts.dtype, s) for _dim in nts.shape.dim: if _dim.name == DimNames.BATCH or \ _dim.name == DimNames.CHANNEL: s.dim.append(Shape.Dim(_dim.name, _dim.size)) elif _dim.name == DimNames.WIDTH or \ _dim.name == DimNames.HEIGHT: s.dim.append( Shape.Dim(_dim.name, int(math.floor(_dim.size * cls.__max_f_hw)))) else: return None return result
def max_transform(cls, nts): if nts.dtype not in cls.allowedTypes: return None s = Shape() image, vektor = False, False result = TypeShape(nts.dtype, s) for _dim in nts.shape.dim: if (_dim.name == DimNames.BATCH or _dim.name == DimNames.WIDTH or _dim.name == DimNames.HEIGHT ): s.dim.append(Shape.Dim(_dim.name, _dim.size)) elif _dim.name == DimNames.UNITS and not image: s.dim.append(Shape.Dim(_dim.name, int(math.ceil(_dim.size * (1 + cls.__max_f))))) # pessimistic estimation vektor = True elif _dim.name == DimNames.CHANNEL and not vektor: s.dim.append(Shape.Dim(_dim.name, int(math.ceil(_dim.size * (1 + cls.__max_f))))) # pessimistic estimation image = True else: return None return result
def min_transform(cls, nts): if nts.dtype not in cls.allowedTypes: return None s = Shape() result = TypeShape(nts.dtype, s) units = 1 num_units = 0 for _dim in nts.shape.dim: if _dim.name == DimNames.BATCH: s.dim.append(Shape.Dim(_dim.name, _dim.size)) elif (_dim.name == DimNames.WIDTH or _dim.name == DimNames.HEIGHT or _dim.name == DimNames.CHANNEL): units *= _dim.size elif _dim.name == DimNames.UNITS: units *= _dim.size num_units += 1 else: return None if num_units == 1: return None s.dim.append(Shape.Dim(DimNames.UNITS, units)) return result