def __init__(self, args): class Config: pass self._config = Config() self._config.context = 'cpu' self._config.device_id = 0 self._config.columns_size = 2 self._config.x_length = args.x_length self._config.mlp_model_params_path = args.mlp_model_params_path self._config.labels_path = args.labels_path if not os.path.isfile(self._config.mlp_model_params_path): logger.error("Model params path {} is not found.".format(self._config.mlp_model_params_path)) sys.exit(-1) else: logger.info("Path of the model parameters file is {}.".format(self._config.mlp_model_params_path)) if not os.path.isfile(self._config.labels_path): logger.error("Labels path {} is not found.".format(self._config.labels_path)) sys.exit(-1) else: logger.info("Path of the labels file is {}.".format(self._config.labels_path)) seed(0) logger.info("Running in %s" % self._config.context) self._ctx = get_extension_context(self._config.context, device_id = self._config.device_id) nn.set_default_context(self._ctx) nn.clear_parameters() self._mlp = MLP(self._config) self._labels = None with open(self._config.labels_path) as f: self._labels = f.readlines() self._points_buf = pointsbuffer.PointsBuffer()
def __init__(self): self._minx = 0.0 self._miny = 0.0 self._maxx = 255.0 self._maxy = 255.0 self._sigma = 32.0 self._factor = 1.0 self._homography_distort_range = 32.0 self._distortion_level0_repeat = 8 self._distortion_level1_repeat = 8 self._points_buf = pointsbuffer.PointsBuffer() self._max_scale = (self._maxy - self._miny + 1.0) * 0.5 \ if (self._maxx - self._minx) > (self._maxy - self._miny) \ else (self._maxx - self._minx + 1.0) * 0.5 random.seed()
def __init__(self, args): self._config = args self._minx = 0 self._miny = 0 self._maxx = 255 self._maxy = 255 self._output_dir = None self._x = 0 self._y = 0 self._points = [] self._pred_points = [] self._recognizer = None self._window = None self._canvas = None self._result_area = None self._result_txt = None self._points_buf = pointsbuffer.PointsBuffer() self._initWindow()
def __init__(self, args): class Config: pass self._config = Config() self._config.process = 'infer' self._config.columns_size = 2 self._config.x_length = args.x_length self._config.x_input_length = args.x_input_length self._config.x_split_step = args.x_split_step self._config.width = args.width self._config.height = args.height self._config.lstm_units = args.lstm_units self._config.batch_size = 1 self._config.epochs = 0 self._config.validation_split = 0.0 self._config.learning_rate = 0.0 self._config.training_dataset_path = None self._config.evaluation_dataset_path = None self._net_type = args.net logger.info("Network type is {}.".format(self._net_type)) self._mlp = None self._lenet = None self._lstm = None if self._net_type == 'mlp': self._config.model_params_path = args.mlp_model_params_path if not os.path.isfile(self._config.model_params_path): logger.error("Model params path {} is not found.".format( self._config.model_params_path)) else: logger.info("Path of the model parameters file is {}.".format( self._config.model_params_path)) self._mlp = MLP(self._config) self._mlp.init_for_infer() elif self._net_type == 'lenet': self._config.model_params_path = args.lenet_model_params_path if not os.path.isfile(self._config.model_params_path): logger.error("Model params path {} is not found.".format( self._config.model_params_path)) else: logger.info("Path of the model parameters file is {}.".format( self._config.model_params_path)) self._lenet = LeNet(self._config) self._lenet.init_for_infer() elif self._net_type == 'mlp-with-lstm': self._config.model_params_path = args.lstm_model_params_path if not os.path.isfile(self._config.model_params_path): logger.error("Model params path {} is not found.".format( self._config.model_params_path)) else: logger.info("Path of the model parameters file is {}.".format( self._config.model_params_path)) self._lstm = LSTM(self._config) self._lstm.init_for_infer() self._config.model_params_path = args.mlp_model_params_path if not os.path.isfile(self._config.model_params_path): logger.error("Model params path {} is not found.".format( self._config.model_params_path)) else: logger.info("Path of the model parameters file is {}.".format( self._config.model_params_path)) self._mlp = MLP(self._config) self._mlp.init_for_infer() else: raise ValueError("Unknown network type {}".format(self._net_type)) self._labels = None self._labels_path = args.labels_path if not os.path.isfile(self._labels_path): logger.error("Labels path {} is not found.".format( self._labels_path)) else: logger.info("Path of the labels file is {}.".format( self._labels_path)) with open(self._labels_path) as f: self._labels = f.readlines() self._points_buf = pointsbuffer.PointsBuffer()
def __init__(self, args): class Config: pass self._config = Config() self._config.context = args.context self._config.device_id = args.device_id self._config.process = 'infer' self._config.columns_size = 2 self._config.x_length = args.x_length self._config.x_input_length = args.x_input_length self._config.x_output_length = args.x_output_length self._config.x_split_step = args.x_split_step self._config.width = args.width self._config.height = args.height self._config.lstm_unit_name = args.lstm_unit_name self._config.lstm_units = args.lstm_units self._config.batch_size = 1 self._config.max_iter = 0 self._config.learning_rate = 0.0 self._config.weight_decay = 0.0 self._config.val_interval = 0 self._config.val_iter = 0 self._config.monitor_path = '.' self._config.training_dataset_path = None self._config.validation_dataset_path = None self._config.evaluation_dataset_path = None seed(0) if self._config.context is None: self._config.context = 'cpu' logger.info("Running in %s" % self._config.context) self._ctx = get_extension_context(self._config.context, device_id=self._config.device_id) nn.set_default_context(self._ctx) self._net_type = args.net logger.info("Network type is {}.".format(self._net_type)) self._mlp = None self._lenet = None self._lstm = None nn.clear_parameters() if self._net_type == 'mlp': self._config.model_params_path = args.mlp_model_params_path if not os.path.isfile(self._config.model_params_path): logger.error("Model params path {} is not found.".format( self._config.model_params_path)) else: logger.info("Path of the model parameters file is {}.".format( self._config.model_params_path)) self._mlp = MLP(self._config) self._mlp.init_for_infer() elif self._net_type == 'lenet': self._config.model_params_path = args.lenet_model_params_path if not os.path.isfile(self._config.model_params_path): logger.error("Model params path {} is not found.".format( self._config.model_params_path)) else: logger.info("Path of the model parameters file is {}.".format( self._config.model_params_path)) self._lenet = LeNet(self._config) self._lenet.init_for_infer() elif self._net_type == 'mlp-with-lstm': self._config.model_params_path = args.lstm_model_params_path if not os.path.isfile(self._config.model_params_path): logger.error("Model params path {} is not found.".format( self._config.model_params_path)) else: logger.info("Path of the model parameters file is {}.".format( self._config.model_params_path)) self._lstm = LSTM(self._config) self._lstm.init_for_infer() self._config.model_params_path = args.mlp_model_params_path if not os.path.isfile(self._config.model_params_path): logger.error("Model params path {} is not found.".format( self._config.model_params_path)) else: logger.info("Path of the model parameters file is {}.".format( self._config.model_params_path)) self._mlp = MLP(self._config) self._mlp.init_for_infer() else: raise ValueError("Unknown network type {}".format(self._net_type)) self._labels = None self._labels_path = args.labels_path if not os.path.isfile(self._labels_path): logger.error("Labels path {} is not found.".format( self._labels_path)) else: logger.info("Path of the labels file is {}.".format( self._labels_path)) with open(self._labels_path) as f: self._labels = f.readlines() self._points_buf = pointsbuffer.PointsBuffer()