def __init__(self, input_shape, output_images, kernel_size, activation_fn, learned_parameters=None): Layer.__init__( self, [input_shape, output_images, kernel_size, activation_fn]) self.__input_shape = input_shape self.__filter_shape = (output_images, input_shape[0], kernel_size, kernel_size) self.__activation_fn = activation_fn if learned_parameters == None: n_out = np.prod(self.__filter_shape) / (output_images * 4) self.__weights = theano.shared(value=np.random.normal( 0.0, 1.0 / np.sqrt(n_out), self.__filter_shape).astype('float32'), borrow=True) self.__biases = theano.shared(value=np.random.normal( 0.0, 1.0, output_images).astype('float32'), borrow=True) else: self.__weights = theano.shared(value=np.asarray( learned_parameters[0], 'float32'), borrow=True) self.__biases = theano.shared(value=np.asarray( learned_parameters[1], 'float32'), borrow=True) self.params = [self.__weights, self.__biases]
def __init__(self, config, output_folder, net): Layer.__init__(self, config) if 'gt_machine_color' in self.settings: for cls in self.settings['gt_machine_color']: col = self.settings['gt_machine_color'][cls] # @TODO: is it required? # if np.min(col) != np.max(col): # raise ValueError('"gt_machine_color"s should have equal rgb values, e.g.: [3, 3, 3].') if np.min(col) < 0: raise ValueError('Minimum "gt_machine_color" should be [0, 0, 0].') for _, flag_name, mapping_name in self.odir_flag_mapping: if self.settings[flag_name]: if mapping_name not in self.settings: raise ValueError("Color mapping {} required if {} is true.".format(mapping_name, flag_name)) # @TODO: maybe check if all classes are present target_arr = ['masks_machine', 'masks_human'] target_determ = any((self.settings[x] for x in target_arr)) if not target_determ: raise ValueError("Some output target ({}) should be set to true.".format(', '.join(target_arr))) self.output_folder = output_folder self.net = net self.out_project = sly.Project(directory=output_folder, mode=sly.OpenMode.CREATE) # Deprecate warning for param in ['images', 'annotations']: if param in self.settings: sly.logger.warning("'save_masks' layer: '{}' parameter is deprecated. Skipped.".format(param))
def __init__(self, config): Layer.__init__(self, config) self.classes_to_crop, self.classes_to_save = self._get_cls_lists() if len(self.classes_to_crop) == 0: raise ValueError("InstancesCropLayer: classes array can not be empty") if len(set(self.classes_to_crop) & set(self.classes_to_save)) > 0: raise ValueError("InstancesCropLayer: classes and save_classes must not intersect")
def __init__(self, config, output_folder, net): Layer.__init__(self, config) self.output_folder = output_folder self.net = net self.out_project = sly.Project(directory=output_folder, mode=sly.OpenMode.CREATE) self.net_change_images = self.net.may_require_images()
def __init__(self, in_size, out_size, activation_fn, learned_parameters=None): Layer.__init__(self, [in_size, out_size, activation_fn]) self.__in_size = in_size self.__activation_fn = activation_fn if learned_parameters == None: deviation = 1.0 / np.sqrt(in_size) if (activation_fn == T.nnet.softmax): deviation = 0 self.__weights = theano.shared(value=np.random.normal( 0.0, deviation, (in_size, out_size)).astype('float32'), borrow=True) self.__biases = theano.shared(value=np.random.normal( 0.0, deviation, out_size).astype('float32'), borrow=True) else: self.__weights = theano.shared(value=np.asarray( learned_parameters[0], 'float32'), borrow=True) self.__biases = theano.shared(value=np.asarray( learned_parameters[1], 'float32'), borrow=True) self.params = [self.__weights, self.__biases]
def __init__(self, config): Layer.__init__(self, config) if self.is_action_delete: # TODO factor out string constants. if isinstance(self.tag_json, dict) and 'value' in self.tag_json: # TODO relax this. Will require more detailed logic on how to modify the meta (c.f. get_removed_tags()). raise ValueError('Tag removal is only supported by name. Restriction by value is not supported.')
def __init__(self, config, output_folder, net): Layer.__init__(self, config) if 'gt_machine_color' in self.settings: for cls in self.settings['gt_machine_color']: col = self.settings['gt_machine_color'][cls] # @TODO: is it required? # if np.min(col) != np.max(col): # raise ValueError('"gt_machine_color"s should have equal rgb values, e.g.: [3, 3, 3].') if np.min(col) < 0: raise ValueError( 'Minimum "gt_machine_color" should be [0, 0, 0].') for _, flag_name, mapping_name in self.odir_flag_mapping: if self.settings[flag_name]: if mapping_name not in self.settings: raise ValueError( "Color mapping {} required if {} is true.".format( mapping_name, flag_name)) # @TODO: maybe check if all classes are present target_arr = ['images', 'annotations', 'masks_machine', 'masks_human'] target_determ = any((self.settings[x] for x in target_arr)) if not target_determ: raise ValueError( "Some output target ({}) should be set to true.".format( ', '.join(target_arr))) self.output_folder = output_folder self.net = net self.pr_writer = sly.ProjectWriterFS(output_folder)
def __init__(self, config, output_folder, net): Layer.__init__(self, config) if not self.settings['images'] and not self.settings['annotations']: raise ValueError("images or annotations should be set to true") self.output_folder = output_folder self.net = net self.pr_writer = ProjectWriterFS(output_folder)
def __init__(self, config): Layer.__init__(self, config) condition = list(self.settings['condition'].keys())[0] if condition == 'project_datasets': project_datasets = self.settings['condition'][condition] for project_dataset_str in project_datasets: self._check_project_dataset_str(project_dataset_str)
def __init__(self, config): Layer.__init__(self, config) window_wh = (self.settings['window']['width'], self.settings['window']['height']) min_overlap_xy = (self.settings['min_overlap']['x'], self.settings['min_overlap']['y']) self.sliding_windows = SlidingWindows( window_wh, min_overlap_xy) # + some validating
def __init__(self): Layer.__init__(self, None) uh.set_layout(uh.PHAT) self.mWidth = 4 self.mHeight = 8 # mValues is a mWidth x mHeight array of tuples formatted # as (r, g, b) values for that pixel. self.mValues = [[(0, 0, 0) for x in range(self.mWidth)] for y in range(self.mHeight)]
def __init__(self, in_size=3, out_size=3, weights=None): """ :param in_size: :param out_size: :param weights: :return: """ Layer.__init__(self, in_size, out_size, weights)
def __init__(self, config): Layer.__init__(self, config) def check_min_max(dictionary, text): if dictionary['min'] > dictionary['max']: raise RuntimeError( '"min" should be <= than "max" for "{}".'.format(text)) check_min_max(self.settings['contrast'], 'contrast') check_min_max(self.settings['brightness'], 'brightness')
def __init__(self, layer, fontName, ch): Layer.__init__(self, layer) if fontName == "atari": self.mFont = FontAtariSmall() elif fontName == "quarky": self.mFont = FontQuarkyDotMatrix() else: raise Exeption("Cannot instantiate font %s" % fontName) print "Created %s font" % fontName self.mFont.setCharacter(ch)
def __init__(self, config, input_project_metas): Layer.__init__(self, config) self._define_layer_project() in_project_meta = input_project_metas.get(self.project_name, None) if in_project_meta is None: raise ValueError( 'Data Layer can not init corresponding project meta. ' 'Project name ({}) not found'.format(self.project_name)) self.in_project_meta = deepcopy(in_project_meta)
def __init__(self, boolean): ''' Constructor ''' Layer.__init__(self) self.closure = None self.should_update = boolean self.text_sources = [] self.image_sources = [] self.point_sources = [] self.line_sources = [] self.astro_sources = []
def __init__(self, config): Layer.__init__(self, config) if self.settings['height'] * self.settings['width'] == 0: raise RuntimeError(self, '"height" and "width" should be != 0.') if self.settings['height'] + self.settings['width'] == -2: raise RuntimeError( self, '"height" and "width" cannot be both set to -1.') if self.settings['height'] * self.settings['width'] < 0: if not self.settings['aspect_ratio']['keep']: raise RuntimeError( self, '"keep" "aspect_ratio" should be set to "true" ' 'when "width" or "height" is -1.')
def __init__(self, boolean): """ Constructor """ Layer.__init__(self) self.closure = None self.should_update = boolean self.text_sources = [] self.image_sources = [] self.point_sources = [] self.line_sources = [] self.astro_sources = []
def __init__(self, config): Layer.__init__(self, config) if (self.settings['name'] == 'median') and (self.settings['kernel'] % 2 == 0): raise RuntimeError('Kernel for median blur must be odd.') def check_min_max(dictionary, text): if dictionary['min'] > dictionary['max']: raise RuntimeError( '"min" should be <= than "max" for "{}".'.format(text)) if self.settings['name'] == 'gaussian': check_min_max(self.settings['sigma'], 'sigma')
def __init__(self, config, output_folder, net): Layer.__init__(self, config) self.output_folder = output_folder self.net = net self.out_project = sly.Project(directory=output_folder, mode=sly.OpenMode.CREATE) # Deprecate warning for param in ['images', 'annotations']: if param in self.settings: sly.logger.warning( "'save' layer: '{}' parameter is deprecated. Skipped.". format(param))
def __init__(self, Para): Layer.__init__(self,Para) self.bias = False # no bias term by default # The following names needs to be defined by inheriting layers self.outChannel = None self.W = None self.b = None self.dW = None self.db = None # for Momentum optimizer self.vdW = None self.vdb = None self.WShape = None # used to initialize W self.inpNum = 0 # total number of input
def __init__(self, config): Layer.__init__(self, config) if 'random_part' in self.settings: random_part = self.settings['random_part'] keep_aspect_ratio = random_part.get('keep_aspect_ratio', False) if keep_aspect_ratio: if random_part['height'] != random_part['width']: raise RuntimeError("When 'keep_aspect_ratio' is 'true', 'height' and 'width' should be equal.") def check_min_max(dictionary, text): if dictionary['min_percent'] > dictionary['max_percent']: raise RuntimeError("'min_percent' should be <= than 'max_percent' for {}".format(text)) check_min_max(random_part['height'], 'height') check_min_max(random_part['width'], 'width')
def __init__(self,parent_widget): Layer.__init__(self, 'Target Layer', parent_widget) self._cross = None
def __init__(self,resolution_meter,parent_widget): Layer.__init__(self,'Path Layer', parent_widget) self._resolution_meter = resolution_meter self._path_queue = deque( maxlen=60) self._last_pos = (0,0,0)
def __init__(self, name, orig=None): Layer.__init__(self, name, orig) self.seed_gui = SeedingGUI() if orig == None else orig.seed_gui self.range_gui = RangeGUI() if orig == None else orig.range_gui
def __init__(self, layer, foreground, background): Layer.__init__(self, layer) assert (len(foreground) == 3) assert (len(background) == 3) self.mForeground = foreground self.mBackground = background
def __init__(self,para): Layer.__init__(self,para) self.layerList = []
def __init__(self, layer): Layer.__init__(self, layer)
def __init__(self, config): Layer.__init__(self, config) self.src_check_mappings = [self.settings['class']]
def __init__(self, resolution_meter, parent_widget): Layer.__init__(self, 'Submarine Layer', parent_widget) self._resolution_meters = resolution_meter self.subModel = loader(parent_widget) stl_file = os.path.join(rospkg.RosPack().get_path('rqt_navigation_map'), 'resource', 'sub.stl') self.subModel.load_binary_stl(stl_file)
def __init__(self,parent_widget): Layer.__init__(self,'Coordinate Layer',parent_widget)
def __init__(self, para): Layer.__init__(self, para)
def __init__(self, config): Layer.__init__(self, config) self.params = self.settings['filter_by']['polygon_sizes'] if self.params['action'] != 'delete': raise NotImplementedError('Class remapping is NIY here.')
def __init__(self,resolution_meter,parent_widget): Layer.__init__(self,'Grid Layer',parent_widget) self._resolution_meters = resolution_meter self._lock = threading.Lock()
def __init__(self, config, output_folder, net): Layer.__init__(self, config) self.output_folder = output_folder self.net = net self.pr_writer = ProjectWriterFS(output_folder) self.net_change_images = self.net.may_require_images()
def __init__(self, config): Layer.__init__(self, config) if self.settings['rotate_angles']['min_degrees'] > self.settings[ 'rotate_angles']['max_degrees']: raise RuntimeError('"min_degrees" should be <= "max_degrees"')
def __init__(self, config): Layer.__init__(self, config)
def __init__(self, config): Layer.__init__(self, config) if self.settings['min_points_number'] < 0: raise ValueError( "GenerateHintsLayer: min_points_number must not be less than zero" )