Koushik Dutta commited on
Commit
45d0854
·
1 Parent(s): 170246d

calibration

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.jpg filter=lfs diff=lfs merge=lfs -text
.gitignore CHANGED
@@ -2,4 +2,6 @@
2
  vision.pt
3
  text.pt
4
  *pnnx*
5
- *_ncnn.py
 
 
 
2
  vision.pt
3
  text.pt
4
  *pnnx*
5
+ *_ncnn.py
6
+ __pycache__
7
+
calibration.py DELETED
@@ -1,41 +0,0 @@
1
- text_input_calibration_samples = [
2
- "man with backpack", "person walking dog", "car parked in driveway",
3
- "delivery man", "UPS truck", "FedEx truck", "Amazon delivery",
4
- "woman with groceries", "child playing", "dog near gate",
5
- "unknown person approaching", "motion detected", "vehicle on driveway",
6
- "suspicious activity", "someone at the door", "person in backyard",
7
- "car driving away", "truck on street", "package delivered",
8
- "stranger near front door", "man wearing a hat", "person in black jacket",
9
- "person with red bag", "bicycle near fence", "dog in yard",
10
- "person running", "car entering driveway", "person in garden",
11
- "no one in view", "snowy scene", "night vision footage",
12
- "package left at door", "person holding something", "person climbing fence",
13
- "cat in yard", "truck backing up", "bike leaning on wall",
14
- "person walking", "car parked outside", "motion detected at night",
15
- "woman in red dress", "man in blue shirt", "person in hoodie",
16
- "person in sunglasses", "dog running", "car with unknown license plate",
17
- "person with umbrella", "package pickup", "snow falling",
18
- "person approaching house", "truck on driveway", "delivery vehicle parked",
19
- "child riding bike", "person in white shirt", "man on phone",
20
- "suspicious vehicle", "package delivered", "motion near garage",
21
- "person wearing mask", "dog on porch", "truck driving by",
22
- "person walking past house", "car idling", "person leaving house",
23
- "woman on porch", "man in gray jacket", "person with package",
24
- "unknown person at gate", "package on doorstep", "person walking dog at night",
25
- "vehicle at front door", "person wearing cap", "suspicious delivery person",
26
- "dog chasing car", "truck parked in front", "child walking alone",
27
- "person wearing backpack", "car pulling into driveway", "motion near window",
28
- "delivery package dropped", "person with camera", "man in uniform",
29
- "woman in yellow dress", "person wearing gloves", "car driving fast",
30
- "person entering gate", "truck leaving area", "package picked up",
31
- "motion near mailbox", "suspicious man", "suspicious woman",
32
- "person with box", "person with shopping bag", "dog near garage",
33
- "person wearing jacket", "truck with logo", "suspicious backpack",
34
- "child playing near car", "person in front yard", "motion detected at gate",
35
- "package delivery", "person walking fast", "truck making delivery",
36
- "man with camera", "person near fence", "suspicious car parked",
37
- "person wearing gloves", "vehicle in backyard", "motion near porch",
38
- "person with package in hand", "truck with delivery sign", "child on bike",
39
- "person standing still", "car with lights on", "suspicious vehicle in front",
40
- "woman with shopping bags", "person wearing jeans", "suspicious dog",
41
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
export.py CHANGED
@@ -3,7 +3,6 @@ from PIL import Image
3
  import requests
4
  from transformers import CLIPProcessor, CLIPModel
5
  from transformers.models.clip.modeling_clip import _get_vector_norm
6
- import coremltools as ct
7
  import torch
8
  import numpy as np
9
  import platform
@@ -69,6 +68,7 @@ with torch.no_grad():
69
  traced_text_model = torch.jit.trace(text, (inputs.data['input_ids'], inputs.data['attention_mask']))
70
 
71
  def convert_coreml():
 
72
  coreml_model = ct.convert(traced_vision_model, inputs=[ct.TensorType(shape=inputs.data['pixel_values'].shape)])
73
  coreml_model.save('vision.mlpackage')
74
 
@@ -78,6 +78,7 @@ def convert_coreml():
78
  # convert_coreml()
79
 
80
  def infer_coreml():
 
81
  coreml_vision_model = ct.models.MLModel('vision.mlpackage')
82
  coreml_text_model = ct.models.MLModel('text.mlpackage')
83
 
@@ -164,6 +165,48 @@ def infer_openvino():
164
 
165
  # infer_openvino()
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
 
168
  def export_ncnn():
169
  traced_vision_model.save(f"vision.pt")
@@ -175,7 +218,7 @@ def export_ncnn():
175
  input_shape2_str = json.dumps(list(inputs.data['attention_mask'].shape)).replace(" ", "")
176
  os.system(f"pnnx text.pt 'inputshape={input_shape_str}i64,{input_shape2_str}i64'")
177
 
178
- export_ncnn()
179
 
180
  def infer_ncnn():
181
  import ncnn
 
3
  import requests
4
  from transformers import CLIPProcessor, CLIPModel
5
  from transformers.models.clip.modeling_clip import _get_vector_norm
 
6
  import torch
7
  import numpy as np
8
  import platform
 
68
  traced_text_model = torch.jit.trace(text, (inputs.data['input_ids'], inputs.data['attention_mask']))
69
 
70
  def convert_coreml():
71
+ import coremltools as ct
72
  coreml_model = ct.convert(traced_vision_model, inputs=[ct.TensorType(shape=inputs.data['pixel_values'].shape)])
73
  coreml_model.save('vision.mlpackage')
74
 
 
78
  # convert_coreml()
79
 
80
  def infer_coreml():
81
+ import coremltools as ct
82
  coreml_vision_model = ct.models.MLModel('vision.mlpackage')
83
  coreml_text_model = ct.models.MLModel('text.mlpackage')
84
 
 
165
 
166
  # infer_openvino()
167
 
168
+ def export_openvino_int8():
169
+ import openvino as ov
170
+ import text_calibration
171
+ import image_calibration
172
+ import nncf
173
+
174
+ ov_vision_model = ov.Core().read_model("openvino/vision.xml")
175
+ ov_text_model = ov.Core().read_model("openvino/text.xml")
176
+
177
+ vision_calibration_dataset = image_calibration.get_image_calibration_data()
178
+ text_calibration_dataset = text_calibration.get_text_calibration_data()
179
+
180
+ vision_dataset = nncf.Dataset(vision_calibration_dataset)
181
+ text_dataset = nncf.Dataset(text_calibration_dataset)
182
+
183
+ quantized_vision_model = nncf.quantize(ov_vision_model, vision_dataset, preset=nncf.QuantizationPreset.MIXED)
184
+ quantized_text_model = nncf.quantize(ov_text_model, text_dataset, preset=nncf.QuantizationPreset.MIXED)
185
+
186
+ ov.save_model(quantized_vision_model, "openvino/vision_int8.xml")
187
+ ov.save_model(quantized_text_model, "openvino/text_int8.xml")
188
+
189
+ # export_openvino_int8()
190
+
191
+ def infer_openvino_int8():
192
+ import openvino as ov
193
+ ov_vision_model = ov.Core().read_model("openvino/vision_int8.xml")
194
+ ov_text_model = ov.Core().read_model("openvino/text_int8.xml")
195
+
196
+ compiled_vision_model = ov.Core().compile_model(ov_vision_model, "CPU")
197
+ compiled_text_model = ov.Core().compile_model(ov_text_model, "CPU")
198
+
199
+ vision_predictions = compiled_vision_model(inputs.data['pixel_values'])
200
+ text_predictions = compiled_text_model((inputs.data['input_ids'], inputs.data['attention_mask']))
201
+
202
+ image_embeds = vision_predictions[0]
203
+ text_embeds = text_predictions[0]
204
+
205
+ logits_per_text = text_embeds @ image_embeds.T
206
+
207
+ print("similarity:", logits_per_text.item())
208
+
209
+ infer_openvino_int8()
210
 
211
  def export_ncnn():
212
  traced_vision_model.save(f"vision.pt")
 
218
  input_shape2_str = json.dumps(list(inputs.data['attention_mask'].shape)).replace(" ", "")
219
  os.system(f"pnnx text.pt 'inputshape={input_shape_str}i64,{input_shape2_str}i64'")
220
 
221
+ # export_ncnn()
222
 
223
  def infer_ncnn():
224
  import ncnn
image_calibration.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from PIL import Image
3
+ from transformers import CLIPProcessor
4
+ import os
5
+
6
+ def get_image_list():
7
+ # Get list of all files in images directory
8
+ image_files = os.listdir('images/')
9
+
10
+ # Filter for .jpg files only
11
+ jpg_files = [f"images/{f}" for f in image_files if f.endswith('.jpg')]
12
+
13
+ return jpg_files
14
+
15
+
16
+ def get_image_calibration_data():
17
+ processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
18
+
19
+ calibration_data = []
20
+ for image_file in get_image_list():
21
+ image_path = os.path.join(image_file)
22
+ image = Image.open(image_path)
23
+ inputs = processor(images=image, return_tensors="pt", padding="max_length", truncation=True)
24
+ calibration_data.append(inputs.data["pixel_values"])
25
+
26
+ return calibration_data
images/000000001999.jpg ADDED

Git LFS Details

  • SHA256: bcb3d625f9c8f3c0324248ebd0c8878d5997a033d87e5f876c671c9e27b9e772
  • Pointer size: 131 Bytes
  • Size of remote file: 241 kB
images/000000003899.jpg ADDED

Git LFS Details

  • SHA256: 786d7351b6b1427c108254196fd6680beec48dc539b195d9338ee48aae82417e
  • Pointer size: 131 Bytes
  • Size of remote file: 182 kB
images/000000006712.jpg ADDED

Git LFS Details

  • SHA256: c380ec2421696d6eae3de5c21d258ad5784323baaa7d74f227e79f1fb673bf21
  • Pointer size: 131 Bytes
  • Size of remote file: 196 kB
images/000000009658.jpg ADDED

Git LFS Details

  • SHA256: 03f80991a44774e28bc9e9f45b083841880b751ed9b8095aa5f75ec093f851d6
  • Pointer size: 130 Bytes
  • Size of remote file: 75.7 kB
images/000000012999.jpg ADDED

Git LFS Details

  • SHA256: 47afe48f9b1dffacda63ba1bc96fe98d5b196c94504070277ba5016937ad78ae
  • Pointer size: 131 Bytes
  • Size of remote file: 308 kB
images/000000013517.jpg ADDED

Git LFS Details

  • SHA256: c3e457bee8c81349095a73f462d03e50f35d578fe8b4d19effa5619db50ff27a
  • Pointer size: 131 Bytes
  • Size of remote file: 168 kB
images/000000017153.jpg ADDED

Git LFS Details

  • SHA256: 760f3d08480e3809521c6ed7babe670ddab22195819ae0f4e55f3216e16728af
  • Pointer size: 131 Bytes
  • Size of remote file: 204 kB
images/000000020063.jpg ADDED

Git LFS Details

  • SHA256: b4aaa7d54b0f7cf6dbad7f57d8897547076c7bd61833e0b6bf2981b03ba1e491
  • Pointer size: 130 Bytes
  • Size of remote file: 92.5 kB
images/000000024307.jpg ADDED

Git LFS Details

  • SHA256: c101a85b2bcfe19b9f68cbd1a88c8b97787a770d421718371f7bcb10151b4e63
  • Pointer size: 131 Bytes
  • Size of remote file: 176 kB
images/000000024457.jpg ADDED

Git LFS Details

  • SHA256: e2ae003710dd9ceccc034a6836e8f1401768e6713514fa3a6e7d4c277a00c11e
  • Pointer size: 130 Bytes
  • Size of remote file: 93.9 kB
images/000000028127.jpg ADDED

Git LFS Details

  • SHA256: f3d4d42151c546a4d7ec8ae8034b13d2380eddde6119b1d2a7edbc5488696c0f
  • Pointer size: 131 Bytes
  • Size of remote file: 178 kB
images/000000029161.jpg ADDED

Git LFS Details

  • SHA256: 6831696caa30568420e03e1bcce58f37c1ddc7b2b10380aef4df6f3d94fa0c0f
  • Pointer size: 131 Bytes
  • Size of remote file: 151 kB
images/000000029716.jpg ADDED

Git LFS Details

  • SHA256: ff57df85ff7d87340f5dd8c65c1b43fc6c9e7fe04d9c4910d42ce9977be3df01
  • Pointer size: 131 Bytes
  • Size of remote file: 279 kB
images/000000030677.jpg ADDED

Git LFS Details

  • SHA256: 764dc5e51466df0bf7e62b5fc6d359aedb3d4ce09be4529b926ac8ea5338c612
  • Pointer size: 131 Bytes
  • Size of remote file: 139 kB
images/000000033300.jpg ADDED

Git LFS Details

  • SHA256: c17ec5a6df3c7ee05ded960a57a930a6acbae0ec95deed7f80304b292c652333
  • Pointer size: 130 Bytes
  • Size of remote file: 73 kB
images/000000033888.jpg ADDED

Git LFS Details

  • SHA256: f26195be0359fa0651fe77abed85660d7b151e77cb57879ca8e5b8f2f6568adf
  • Pointer size: 130 Bytes
  • Size of remote file: 80.9 kB
images/000000034973.jpg ADDED

Git LFS Details

  • SHA256: 2c44d54be453937f88df5976d8c0d1cdcfbd5cc39868d531bf447f68ad7382b9
  • Pointer size: 131 Bytes
  • Size of remote file: 146 kB
images/000000036693.jpg ADDED

Git LFS Details

  • SHA256: 36526cd5e3b22db7ef619023a424de283961652941cc694adb52230e901deab5
  • Pointer size: 130 Bytes
  • Size of remote file: 88.6 kB
images/000000038226.jpg ADDED

Git LFS Details

  • SHA256: f9b967bb910627160b31456074d27cfad32637d3ad359ca0f238f6f7860a5c22
  • Pointer size: 131 Bytes
  • Size of remote file: 244 kB
images/000000038999.jpg ADDED

Git LFS Details

  • SHA256: 32d8e72e288e891d67dbfabcfb2b48d25f7bd98212dca8adf183e81dad001a0e
  • Pointer size: 131 Bytes
  • Size of remote file: 230 kB
images/000000039764.jpg ADDED

Git LFS Details

  • SHA256: 50253d5a8f9bee2392baf44b5cb2c149fa6061b09f0763a3eff0dcd8e15c7d1b
  • Pointer size: 131 Bytes
  • Size of remote file: 193 kB
images/000000040380.jpg ADDED

Git LFS Details

  • SHA256: b1df65dccf479b07a6e1f9b3065313880e3f51838cc1bd3009856105cced2ddd
  • Pointer size: 131 Bytes
  • Size of remote file: 137 kB
images/000000040768.jpg ADDED

Git LFS Details

  • SHA256: 284535e8fcd92219115aed9c15902ae23f39e8c61fe7c36e3bca76cde134b34b
  • Pointer size: 131 Bytes
  • Size of remote file: 104 kB
images/000000040870.jpg ADDED

Git LFS Details

  • SHA256: 1ad08660c6aa85181157e6df4c23554f6654e38a802debd95de1a7e25e9160c8
  • Pointer size: 131 Bytes
  • Size of remote file: 106 kB
images/000000042404.jpg ADDED

Git LFS Details

  • SHA256: b875bb3ec206349d370ab7b3293c57a1be3959e3b22abb6220b56fb0fd60df4b
  • Pointer size: 131 Bytes
  • Size of remote file: 111 kB
images/000000044446.jpg ADDED

Git LFS Details

  • SHA256: 34ea9dab209dc01e552014001c9f3a9ff8f3fb13500b3abc840cf4c3f88f131e
  • Pointer size: 131 Bytes
  • Size of remote file: 284 kB
images/000000047942.jpg ADDED

Git LFS Details

  • SHA256: 06f8d51db3561727256d6003ff157df7072f104f69ac0f378f465418aba7f23f
  • Pointer size: 131 Bytes
  • Size of remote file: 234 kB
images/000000048491.jpg ADDED

Git LFS Details

  • SHA256: ccb8cc39541f004bb94379bd66d5444303c460097d4f377b8003aa27d5f62d24
  • Pointer size: 131 Bytes
  • Size of remote file: 216 kB
images/000000048595.jpg ADDED

Git LFS Details

  • SHA256: 205b47fd4ac24974a76f2dded08eb38b715fb860912c6f164b142450a4b12f18
  • Pointer size: 131 Bytes
  • Size of remote file: 182 kB
images/000000053977.jpg ADDED

Git LFS Details

  • SHA256: addfa4db24b8062892f0804ddb5309857bdda301ccbb3020295686293cb1f76d
  • Pointer size: 131 Bytes
  • Size of remote file: 104 kB
images/000000061834.jpg ADDED

Git LFS Details

  • SHA256: c1e94587151efecba8ce9be4e7cde5403a196370d2e6544fdb0532ce5bd5ddb9
  • Pointer size: 130 Bytes
  • Size of remote file: 81.6 kB
images/000000061945.jpg ADDED

Git LFS Details

  • SHA256: 2e2f10a518c55207fe5b5d368c385e114a42348d733a43f3e81e10ff3a5c045c
  • Pointer size: 130 Bytes
  • Size of remote file: 92.6 kB
images/000000063409.jpg ADDED

Git LFS Details

  • SHA256: 916527a2f50a7e1df168a62c4fa24967a9bd589d53eef70d7688cb1c4e74a6d4
  • Pointer size: 131 Bytes
  • Size of remote file: 246 kB
images/000000063873.jpg ADDED

Git LFS Details

  • SHA256: 9123deece8b7d1099a9d3af322dc17b8a105e78c89635a868761b6c872e8de06
  • Pointer size: 131 Bytes
  • Size of remote file: 343 kB
images/000000063879.jpg ADDED

Git LFS Details

  • SHA256: 862183d20880f42167e286593a0122db8c959075f649a60669baf9db6efa9be3
  • Pointer size: 130 Bytes
  • Size of remote file: 90.2 kB
images/000000065177.jpg ADDED

Git LFS Details

  • SHA256: 1c7ced9cdaa4513ed38712fd2c061387f57f2931cb83a3bf02d14261281278c0
  • Pointer size: 131 Bytes
  • Size of remote file: 165 kB
images/000000066503.jpg ADDED

Git LFS Details

  • SHA256: d1f1da416a31252c1402597c85d5279e8b5545c0000a8074c93eb6793cc2866f
  • Pointer size: 131 Bytes
  • Size of remote file: 164 kB
images/000000069121.jpg ADDED

Git LFS Details

  • SHA256: 960ceac70576378ebd8a05577aa8aad95042d575142c5d7e31120273cd3be600
  • Pointer size: 130 Bytes
  • Size of remote file: 32.2 kB
images/000000072207.jpg ADDED

Git LFS Details

  • SHA256: 95f45804511e956ecef4ed81762f124cf8d221f2ef2dfb86536f7cbfd79d20fe
  • Pointer size: 131 Bytes
  • Size of remote file: 172 kB
images/000000075257.jpg ADDED

Git LFS Details

  • SHA256: f3d04e07d89dde6d2a7e098ea7b3e63c14466d0d464a5b68c17967eb77c5f0a3
  • Pointer size: 130 Bytes
  • Size of remote file: 79.5 kB
images/000000076428.jpg ADDED

Git LFS Details

  • SHA256: 264a0866f776d9871547e44d1036a2a55178a9dd022d8ba87026989cb48c153a
  • Pointer size: 131 Bytes
  • Size of remote file: 138 kB
images/000000077639.jpg ADDED

Git LFS Details

  • SHA256: a3c1f3b0b468c67f2affa97484e5fe46bb72779de177d325fde78bdd159e7d61
  • Pointer size: 131 Bytes
  • Size of remote file: 192 kB
images/000000077864.jpg ADDED

Git LFS Details

  • SHA256: 4f46dbe2a52a1f38d0d6d9a30e622868c3087a7400ba56d5a0a6b26792f8b254
  • Pointer size: 131 Bytes
  • Size of remote file: 182 kB
images/000000081406.jpg ADDED

Git LFS Details

  • SHA256: 95ad91d7066cd2ca391eb8246a392e497ee4f91274ed68b2403ddd0a9dd98d98
  • Pointer size: 130 Bytes
  • Size of remote file: 64.3 kB
images/000000083755.jpg ADDED

Git LFS Details

  • SHA256: 8cbbc61e1bc71eb1d8304a8dd513896c21bc93eecf906aa32ec90732e9eb5ff9
  • Pointer size: 131 Bytes
  • Size of remote file: 103 kB