__init__.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import gdown
  2. from .efficient_sam import EfficientSam
  3. from .segment_anything_model import SegmentAnythingModel
  4. from .barcode_detect import BarcodeDetectModel
  5. from .barcode_decode import BarcodeDecodeModel
  6. class BarcodeDetect(BarcodeDetectModel):
  7. name="BarcodeDetect(ov)"
  8. def __init__(self, detection_model_path=None, segmentation_model_path=None):
  9. super().__init__(
  10. detection_model_path=detection_model_path,
  11. segmentation_model_path=segmentation_model_path,
  12. # decoding_model_path=decoding_model_path
  13. )
  14. class BarcodeDecode(BarcodeDecodeModel):
  15. name="BarcodeDecode(ov)"
  16. def __init__(self, decoding_model_path=None):
  17. super().__init__(
  18. decoding_model_path=decoding_model_path
  19. )
  20. class SegmentAnythingModelVitB(SegmentAnythingModel):
  21. name = "SegmentAnything (speed)"
  22. def __init__(self,model_path=None):
  23. super().__init__(
  24. encoder_path=gdown.cached_download(
  25. url="https://github.com/wkentaro/labelme/releases/download/sam-20230416/sam_vit_b_01ec64.quantized.encoder.onnx", # NOQA
  26. md5="80fd8d0ab6c6ae8cb7b3bd5f368a752c",
  27. ),
  28. decoder_path=gdown.cached_download(
  29. url="https://github.com/wkentaro/labelme/releases/download/sam-20230416/sam_vit_b_01ec64.quantized.decoder.onnx", # NOQA
  30. md5="4253558be238c15fc265a7a876aaec82",
  31. ),
  32. )
  33. class SegmentAnythingModelVitL(SegmentAnythingModel):
  34. name = "SegmentAnything (balanced)"
  35. def __init__(self,model_path=None):
  36. super().__init__(
  37. encoder_path=gdown.cached_download(
  38. url="https://github.com/wkentaro/labelme/releases/download/sam-20230416/sam_vit_l_0b3195.quantized.encoder.onnx", # NOQA
  39. md5="080004dc9992724d360a49399d1ee24b",
  40. ),
  41. decoder_path=gdown.cached_download(
  42. url="https://github.com/wkentaro/labelme/releases/download/sam-20230416/sam_vit_l_0b3195.quantized.decoder.onnx", # NOQA
  43. md5="851b7faac91e8e23940ee1294231d5c7",
  44. ),
  45. )
  46. class SegmentAnythingModelVitH(SegmentAnythingModel):
  47. name = "SegmentAnything (accuracy)"
  48. def __init__(self,model_path=None):
  49. super().__init__(
  50. encoder_path=gdown.cached_download(
  51. url="https://github.com/wkentaro/labelme/releases/download/sam-20230416/sam_vit_h_4b8939.quantized.encoder.onnx", # NOQA
  52. md5="958b5710d25b198d765fb6b94798f49e",
  53. ),
  54. decoder_path=gdown.cached_download(
  55. url="https://github.com/wkentaro/labelme/releases/download/sam-20230416/sam_vit_h_4b8939.quantized.decoder.onnx", # NOQA
  56. md5="a997a408347aa081b17a3ffff9f42a80",
  57. ),
  58. )
  59. class EfficientSamVitT(EfficientSam):
  60. name = "EfficientSam (speed)"
  61. def __init__(self,model_path=None):
  62. super().__init__(
  63. encoder_path=gdown.cached_download(
  64. url="https://github.com/labelmeai/efficient-sam/releases/download/onnx-models-20231225/efficient_sam_vitt_encoder.onnx", # NOQA
  65. md5="2d4a1303ff0e19fe4a8b8ede69c2f5c7",
  66. ),
  67. decoder_path=gdown.cached_download(
  68. url="https://github.com/labelmeai/efficient-sam/releases/download/onnx-models-20231225/efficient_sam_vitt_decoder.onnx", # NOQA
  69. md5="be3575ca4ed9b35821ac30991ab01843",
  70. ),
  71. )
  72. class EfficientSamVitS(EfficientSam):
  73. name = "EfficientSam (accuracy)"
  74. def __init__(self,model_path=None):
  75. super().__init__(
  76. encoder_path=gdown.cached_download(
  77. url="https://github.com/labelmeai/efficient-sam/releases/download/onnx-models-20231225/efficient_sam_vits_encoder.onnx", # NOQA
  78. md5="7d97d23e8e0847d4475ca7c9f80da96d",
  79. ),
  80. decoder_path=gdown.cached_download(
  81. url="https://github.com/labelmeai/efficient-sam/releases/download/onnx-models-20231225/efficient_sam_vits_decoder.onnx", # NOQA
  82. md5="d9372f4a7bbb1a01d236b0508300b994",
  83. ),
  84. )
  85. MODELS = [
  86. SegmentAnythingModelVitB,
  87. SegmentAnythingModelVitL,
  88. SegmentAnythingModelVitH,
  89. EfficientSamVitT,
  90. EfficientSamVitS,
  91. BarcodeDetect,
  92. BarcodeDecode,
  93. ]