help= " <optional>, it defines the checkpoint for training<fine tuning> or testing", required=False) parser.add_argument( "-image", type=str, help= " <optional>, a filename for an image to be tested in -predict mode-", required=False) pargs = parser.parse_args() if pargs.config != None: configuration_file = pargs.config else: configuration_file = _params.configuration_file configuration = conf.ConfigurationFile(configuration_file, pargs.name) configuration.show() # it is also possible to define the id of the device if pargs.device is None: device_name = "/cpu:0" else: device_name = "/" + pargs.device + ":0" params = {'device': device_name, 'modelname': pargs.name} if pargs.ckpt is not None: params['ckpt'] = pargs.ckpt my_cnn = cnn.CNN(configuration_file, params) run_mode = pargs.mode if run_mode == 'train': my_cnn.train() elif run_mode == 'test': my_cnn.test()
def loadMapping(mapping_file): map_dict = {} with open(mapping_file) as file: lines = [line.rstrip() for line in file] for line in lines: sline = line.split('\t') map_dict[int(sline[1])] = sline[0] return map_dict if __name__ == "__main__": parser = argparse.ArgumentParser(description="signature recognition") parser.add_argument("-image", type=str, help="check image", required=True) input_arg = parser.parse_args() configuration_file = "configuration.config" configuration = conf.ConfigurationFile(configuration_file, "SIMPLE-SIGNATURE-CNN") #loading cnn model _params = { "device": "/cpu:0", "arch": "SIMPLE-SIGNATURE-CNN", "processFun": imgproc.getProcessFun() } sign_cnn = cnn.CNN(configuration_file, _params) filename = input_arg.image image = io.imread(filename, as_gray=True) sign_image = sutils.extractSignature(image) #cv2.imshow("sign", sign_image) #cv2.waitKey() prediction = sign_cnn.predict(sign_image)[0] idx_class = prediction['idx_predicted_class']