def __init__(self, device="cpu"): self.model = CRNN(**model_parameters) model_data = torch.load( dirname(__file__) + '/logs/checkpoints/best_full.pth') self.model.load_state_dict(model_data['model_state_dict']) self.transforms = get_transforms_without_augmentations(device) self.converter = strLabelConverter(alphabet)
def __init__(self, name, state: State, video_reader: VideoReader, model_path): self.name = name self.logger = logging.getLogger(self.name) self.state = state self.video_reader = video_reader self.ocr_thread = None self.time_start = datetime.now() self.stopped = False converter = strLabelConverter(CV_CONFIG.get('alphabet')) self.predictor = Predictor(model_path, converter) #TODO: Your Predictor self.logger.info("Create OcrStream")
def __init__( self, name, state: State, video_reader: VideoReader, model_path='/home/alex/final_version_ocr/project (car numbers)/model/model_crnn.pth' ): self.name = name self.logger = logging.getLogger(self.name) self.state = state self.video_reader = video_reader self.ocr_thread = None self.time_start = datetime.now() self.stopped = False converter = strLabelConverter(CV_CONFIG.get('alphabet')) self.predictor = Predictor(model_path, converter) self.logger.info("Create OcrStream")
def __init__(self, model_path, transform, device="cuda"): alphabet = " " alphabet += string.ascii_uppercase alphabet += "".join([str(i) for i in range(10)]) MODEL_PARAMS = { "image_height": 32, "number_input_channels": 3, "number_class_symbols": len(alphabet) + 1, "rnn_size": 64 } state_dict = torch.load(model_path, map_location='cpu')['model_state_dict'] self.model = CRNN(**MODEL_PARAMS) self.model.load_state_dict(state_dict) self.model = self.model.to(device) self.model = self.model.eval() self.device = device self.converter = strLabelConverter(alphabet) self.transform = transform
}), "alphabet": CV_CONFIG.get('alphabet'), "loss": { "reduction": 'mean' }, "optimizer": ("Adam", { "lr": 0.001 }), # CHANGE DEVICE IF YOU USE GPU "device": "cpu", } if __name__ == "__main__": converter = strLabelConverter(MODEL_PARAMS['alphabet']) model_path = EXPERIMENT_DIR / sorted( os.listdir(EXPERIMENT_DIR))[-1] # Last saved model #print('Model path is', model_path) #print('Is it a file?', os.path.isfile(model_path)) predictor = Predictor(model_path, converter, CV_CONFIG.get('ocr_image_size'), device=MODEL_PARAMS['device']) #print('File name', args.file_name) #print(os.path.isdir('/workdir/data/CropNumbers')) #print(os.path.isfile(args.file_name)) if os.path.isdir(args.file_name):
def __init__(self, alphabet, device='cpu'): super().__init__() self.converter = strLabelConverter(alphabet) self.device = device self.loss = nn.CTCLoss()
def __init__(self, params): super().__init__(params) self.converter = strLabelConverter(params["alphabet"])
def __init__(self): self.alphabet = "ABEKMHOPCTYX" + "".join([str(i) for i in range(10)]) + "-" self.encoder = strLabelConverter(self.alphabet)