MCPcopy
hub / github.com/JaidedAI/EasyOCR / getDetectorPath

Method getDetectorPath

easyocr/easyocr.py:235–268  ·  view source on GitHub ↗
(self, detect_network)

Source from the content-addressed store, hash-verified

233 dict_list, model_path, device = self.device, quantize=quantize)
234
235 def getDetectorPath(self, detect_network):
236 if detect_network in self.support_detection_network:
237 self.detect_network = detect_network
238 if self.detect_network == 'craft':
239 from .detection import get_detector, get_textbox
240 elif self.detect_network in ['dbnet18']:
241 from .detection_db import get_detector, get_textbox
242 else:
243 raise RuntimeError("Unsupport detector network. Support networks are craft and dbnet18.")
244 self.get_textbox = get_textbox
245 self.get_detector = get_detector
246 corrupt_msg = 'MD5 hash mismatch, possible file corruption'
247 detector_path = os.path.join(self.model_storage_directory, self.detection_models[self.detect_network]['filename'])
248 if os.path.isfile(detector_path) == False:
249 if not self.download_enabled:
250 raise FileNotFoundError("Missing %s and downloads disabled" % detector_path)
251 LOGGER.warning('Downloading detection model, please wait. '
252 'This may take several minutes depending upon your network connection.')
253 download_and_unzip(self.detection_models[self.detect_network]['url'], self.detection_models[self.detect_network]['filename'], self.model_storage_directory, self.verbose)
254 assert calculate_md5(detector_path) == self.detection_models[self.detect_network]['md5sum'], corrupt_msg
255 LOGGER.info('Download complete')
256 elif calculate_md5(detector_path) != self.detection_models[self.detect_network]['md5sum']:
257 if not self.download_enabled:
258 raise FileNotFoundError("MD5 mismatch for %s and downloads disabled" % detector_path)
259 LOGGER.warning(corrupt_msg)
260 os.remove(detector_path)
261 LOGGER.warning('Re-downloading the detection model, please wait. '
262 'This may take several minutes depending upon your network connection.')
263 download_and_unzip(self.detection_models[self.detect_network]['url'], self.detection_models[self.detect_network]['filename'], self.model_storage_directory, self.verbose)
264 assert calculate_md5(detector_path) == self.detection_models[self.detect_network]['md5sum'], corrupt_msg
265 else:
266 raise RuntimeError("Unsupport detector network. Support networks are {}.".format(', '.join(self.support_detection_network)))
267
268 return detector_path
269
270 def initDetector(self, detector_path):
271 return self.get_detector(detector_path,

Callers 2

__init__Method · 0.95
setDetectorMethod · 0.95

Calls 2

download_and_unzipFunction · 0.85
calculate_md5Function · 0.85

Tested by

no test coverage detected