.gitattributes CHANGED
@@ -33,3 +33,5 @@ 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
37
+ *.png filter=lfs diff=lfs merge=lfs -text
wechat_qr/LICENSE ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Tencent is pleased to support the open source community by making WeChat QRCode available.
2
+
3
+ Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
4
+ The below software in this distribution may have been modified by THL A29 Limited ("Tencent Modifications").
5
+ All Tencent Modifications are Copyright (C) THL A29 Limited.
6
+
7
+ WeChat QRCode is licensed under the Apache License Version 2.0, except for the third-party components listed below.
8
+
9
+ Terms of the Apache License Version 2.0
10
+ --------------------------------------------------------------------
11
+ Apache License
12
+ Version 2.0, January 2004
13
+ http://www.apache.org/licenses/
14
+
15
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
16
+
17
+ 1. Definitions.
18
+
19
+ "License" shall mean the terms and conditions for use, reproduction,
20
+ and distribution as defined by Sections 1 through 9 of this document.
21
+
22
+ "Licensor" shall mean the copyright owner or entity authorized by
23
+ the copyright owner that is granting the License.
24
+
25
+ "Legal Entity" shall mean the union of the acting entity and all
26
+ other entities that control, are controlled by, or are under common
27
+ control with that entity. For the purposes of this definition,
28
+ "control" means (i) the power, direct or indirect, to cause the
29
+ direction or management of such entity, whether by contract or
30
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
31
+ outstanding shares, or (iii) beneficial ownership of such entity.
32
+
33
+ "You" (or "Your") shall mean an individual or Legal Entity
34
+ exercising permissions granted by this License.
35
+
36
+ "Source" form shall mean the preferred form for making modifications,
37
+ including but not limited to software source code, documentation
38
+ source, and configuration files.
39
+
40
+ "Object" form shall mean any form resulting from mechanical
41
+ transformation or translation of a Source form, including but
42
+ not limited to compiled object code, generated documentation,
43
+ and conversions to other media types.
44
+
45
+ "Work" shall mean the work of authorship, whether in Source or
46
+ Object form, made available under the License, as indicated by a
47
+ copyright notice that is included in or attached to the work
48
+ (an example is provided in the Appendix below).
49
+
50
+ "Derivative Works" shall mean any work, whether in Source or Object
51
+ form, that is based on (or derived from) the Work and for which the
52
+ editorial revisions, annotations, elaborations, or other modifications
53
+ represent, as a whole, an original work of authorship. For the purposes
54
+ of this License, Derivative Works shall not include works that remain
55
+ separable from, or merely link (or bind by name) to the interfaces of,
56
+ the Work and Derivative Works thereof.
57
+
58
+ "Contribution" shall mean any work of authorship, including
59
+ the original version of the Work and any modifications or additions
60
+ to that Work or Derivative Works thereof, that is intentionally
61
+ submitted to Licensor for inclusion in the Work by the copyright owner
62
+ or by an individual or Legal Entity authorized to submit on behalf of
63
+ the copyright owner. For the purposes of this definition, "submitted"
64
+ means any form of electronic, verbal, or written communication sent
65
+ to the Licensor or its representatives, including but not limited to
66
+ communication on electronic mailing lists, source code control systems,
67
+ and issue tracking systems that are managed by, or on behalf of, the
68
+ Licensor for the purpose of discussing and improving the Work, but
69
+ excluding communication that is conspicuously marked or otherwise
70
+ designated in writing by the copyright owner as "Not a Contribution."
71
+
72
+ "Contributor" shall mean Licensor and any individual or Legal Entity
73
+ on behalf of whom a Contribution has been received by Licensor and
74
+ subsequently incorporated within the Work.
75
+
76
+ 2. Grant of Copyright License. Subject to the terms and conditions of
77
+ this License, each Contributor hereby grants to You a perpetual,
78
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
79
+ copyright license to reproduce, prepare Derivative Works of,
80
+ publicly display, publicly perform, sublicense, and distribute the
81
+ Work and such Derivative Works in Source or Object form.
82
+
83
+ 3. Grant of Patent License. Subject to the terms and conditions of
84
+ this License, each Contributor hereby grants to You a perpetual,
85
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
86
+ (except as stated in this section) patent license to make, have made,
87
+ use, offer to sell, sell, import, and otherwise transfer the Work,
88
+ where such license applies only to those patent claims licensable
89
+ by such Contributor that are necessarily infringed by their
90
+ Contribution(s) alone or by combination of their Contribution(s)
91
+ with the Work to which such Contribution(s) was submitted. If You
92
+ institute patent litigation against any entity (including a
93
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
94
+ or a Contribution incorporated within the Work constitutes direct
95
+ or contributory patent infringement, then any patent licenses
96
+ granted to You under this License for that Work shall terminate
97
+ as of the date such litigation is filed.
98
+
99
+ 4. Redistribution. You may reproduce and distribute copies of the
100
+ Work or Derivative Works thereof in any medium, with or without
101
+ modifications, and in Source or Object form, provided that You
102
+ meet the following conditions:
103
+
104
+ (a) You must give any other recipients of the Work or
105
+ Derivative Works a copy of this License; and
106
+
107
+ (b) You must cause any modified files to carry prominent notices
108
+ stating that You changed the files; and
109
+
110
+ (c) You must retain, in the Source form of any Derivative Works
111
+ that You distribute, all copyright, patent, trademark, and
112
+ attribution notices from the Source form of the Work,
113
+ excluding those notices that do not pertain to any part of
114
+ the Derivative Works; and
115
+
116
+ (d) If the Work includes a "NOTICE" text file as part of its
117
+ distribution, then any Derivative Works that You distribute must
118
+ include a readable copy of the attribution notices contained
119
+ within such NOTICE file, excluding those notices that do not
120
+ pertain to any part of the Derivative Works, in at least one
121
+ of the following places: within a NOTICE text file distributed
122
+ as part of the Derivative Works; within the Source form or
123
+ documentation, if provided along with the Derivative Works; or,
124
+ within a display generated by the Derivative Works, if and
125
+ wherever such third-party notices normally appear. The contents
126
+ of the NOTICE file are for informational purposes only and
127
+ do not modify the License. You may add Your own attribution
128
+ notices within Derivative Works that You distribute, alongside
129
+ or as an addendum to the NOTICE text from the Work, provided
130
+ that such additional attribution notices cannot be construed
131
+ as modifying the License.
132
+
133
+ You may add Your own copyright statement to Your modifications and
134
+ may provide additional or different license terms and conditions
135
+ for use, reproduction, or distribution of Your modifications, or
136
+ for any such Derivative Works as a whole, provided Your use,
137
+ reproduction, and distribution of the Work otherwise complies with
138
+ the conditions stated in this License.
139
+
140
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
141
+ any Contribution intentionally submitted for inclusion in the Work
142
+ by You to the Licensor shall be under the terms and conditions of
143
+ this License, without any additional terms or conditions.
144
+ Notwithstanding the above, nothing herein shall supersede or modify
145
+ the terms of any separate license agreement you may have executed
146
+ with Licensor regarding such Contributions.
147
+
148
+ 6. Trademarks. This License does not grant permission to use the trade
149
+ names, trademarks, service marks, or product names of the Licensor,
150
+ except as required for reasonable and customary use in describing the
151
+ origin of the Work and reproducing the content of the NOTICE file.
152
+
153
+ 7. Disclaimer of Warranty. Unless required by applicable law or
154
+ agreed to in writing, Licensor provides the Work (and each
155
+ Contributor provides its Contributions) on an "AS IS" BASIS,
156
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
157
+ implied, including, without limitation, any warranties or conditions
158
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
159
+ PARTICULAR PURPOSE. You are solely responsible for determining the
160
+ appropriateness of using or redistributing the Work and assume any
161
+ risks associated with Your exercise of permissions under this License.
162
+
163
+ 8. Limitation of Liability. In no event and under no legal theory,
164
+ whether in tort (including negligence), contract, or otherwise,
165
+ unless required by applicable law (such as deliberate and grossly
166
+ negligent acts) or agreed to in writing, shall any Contributor be
167
+ liable to You for damages, including any direct, indirect, special,
168
+ incidental, or consequential damages of any character arising as a
169
+ result of this License or out of the use or inability to use the
170
+ Work (including but not limited to damages for loss of goodwill,
171
+ work stoppage, computer failure or malfunction, or any and all
172
+ other commercial damages or losses), even if such Contributor
173
+ has been advised of the possibility of such damages.
174
+
175
+ 9. Accepting Warranty or Additional Liability. While redistributing
176
+ the Work or Derivative Works thereof, You may choose to offer,
177
+ and charge a fee for, acceptance of support, warranty, indemnity,
178
+ or other liability obligations and/or rights consistent with this
179
+ License. However, in accepting such obligations, You may act only
180
+ on Your own behalf and on Your sole responsibility, not on behalf
181
+ of any other Contributor, and only if You agree to indemnify,
182
+ defend, and hold each Contributor harmless for any liability
183
+ incurred by, or claims asserted against, such Contributor by reason
184
+ of your accepting any such warranty or additional liability.
185
+
186
+ END OF TERMS AND CONDITIONS
187
+
188
+
189
+
190
+ Other dependencies and licenses:
191
+
192
+ Open Source Software Licensed under the Apache License Version 2.0:
193
+ --------------------------------------------------------------------
194
+ 1. zxing
195
+ Copyright (c) zxing authors and contributors
196
+ Please note this software may have been modified by Tencent.
197
+
198
+ Terms of the Apache License Version 2.0:
199
+ --------------------------------------------------------------------
200
+ Apache License
201
+
202
+ Version 2.0, January 2004
203
+
204
+ http://www.apache.org/licenses/
205
+
206
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
207
+
208
+ 1. Definitions.
209
+
210
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
211
+
212
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
213
+
214
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
215
+
216
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
217
+
218
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
219
+
220
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
221
+
222
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
223
+
224
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
225
+
226
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
227
+
228
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
229
+
230
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
231
+
232
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
233
+
234
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
235
+
236
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
237
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
238
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
239
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
240
+
241
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
242
+
243
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
244
+
245
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
246
+
247
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
248
+
249
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
250
+
251
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
252
+
253
+ END OF TERMS AND CONDITIONS
wechat_qr/README.md ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # WeChatQR — QR Code Detection and Decoding
2
+
3
+ QR code detection and decoding using WeChat CV Team's deep learning models, integrated via OpenCV contrib.
4
+
5
+ ---
6
+
7
+ ## Models
8
+
9
+ | File | Role |
10
+ |---|---|
11
+ | `detect_2026april.onnx` | Detects QR code regions in the image |
12
+ | `sr_2026april.onnx` | Super-resolves each region for better decoding |
13
+
14
+ Both models are passed directly to the `WeChatQRCode` API — no manual preprocessing needed.
15
+
16
+ ---
17
+
18
+ ## Usage
19
+
20
+ ```bash
21
+ python demo.py \
22
+ --detect detect_2026april.onnx \
23
+ --sr sr_2026april.onnx \
24
+ --image example_outputs/input_image.jpg \
25
+ --output example_outputs/output_image.png
26
+ ```
27
+
28
+ ---
29
+
30
+ ## Example Output
31
+
32
+ | Input | Output |
33
+ |---|---|
34
+ | ![input](example_outputs/input_image.jpg) | ![output](example_outputs/output_image.png) |
35
+
36
+ ---
37
+
38
+ ## License
39
+
40
+ See [LICENSE](./LICENSE). Original models by WeChat CV Team.
wechat_qr/demo.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Detect and decode QR codes using OpenCV's WeChatQRCode contrib module.
3
+
4
+ Usage:
5
+ python demo.py \
6
+ --detect detect_2026april.onnx \
7
+ --sr sr_2026april.onnx \
8
+ --image example_outputs/input_image.jpg \
9
+ --output output_image.png
10
+
11
+ Requires: pip install opencv-contrib-python
12
+ """
13
+ import argparse
14
+ import cv2 as cv
15
+
16
+
17
+ def detect_qr(detect_model: str, sr_model: str,
18
+ image_path: str, output_path: str = "output_image.png"):
19
+ img = cv.imread(image_path)
20
+ if img is None:
21
+ raise FileNotFoundError(f"Could not read image: {image_path}")
22
+ print(f"Image size: {img.shape[1]}×{img.shape[0]}")
23
+
24
+ try:
25
+ detector = cv.wechat_qrcode_WeChatQRCode(detect_model, sr_model)
26
+ except AttributeError:
27
+ raise RuntimeError(
28
+ "cv2.wechat_qrcode_WeChatQRCode not found.\n"
29
+ "Install OpenCV with contrib modules:\n"
30
+ " pip install opencv-contrib-python"
31
+ )
32
+
33
+ texts, points = detector.detectAndDecode(img)
34
+
35
+ output_img = img.copy()
36
+ for text, corners in zip(texts, points):
37
+ pts = corners.astype(int)
38
+ cv.polylines(output_img, [pts.reshape(-1, 1, 2)],
39
+ isClosed=True, color=(0, 255, 0), thickness=2)
40
+ origin = (int(pts[0][0]), max(int(pts[0][1]) - 8, 14))
41
+ cv.putText(output_img, text, origin,
42
+ cv.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2, cv.LINE_AA)
43
+
44
+ cv.imwrite(output_path, output_img)
45
+ print(f"Saved annotated image to: {output_path}")
46
+
47
+ if texts:
48
+ print(f"\nDecoded {len(texts)} QR code(s):")
49
+ for i, text in enumerate(texts, 1):
50
+ print(f" [{i}] {text}")
51
+ else:
52
+ print("\nNo QR codes found.")
53
+
54
+ return list(texts)
55
+
56
+
57
+ if __name__ == "__main__":
58
+ parser = argparse.ArgumentParser(
59
+ description="Detect and decode QR codes using WeChatQR ONNX models"
60
+ )
61
+ parser.add_argument("--detect", required=True, help="Path to detect_*.onnx")
62
+ parser.add_argument("--sr", required=True, help="Path to sr_*.onnx")
63
+ parser.add_argument("--image", required=True, help="Path to input image")
64
+ parser.add_argument("--output", default="output_image.png",
65
+ help="Path for annotated output (default: output_image.png)")
66
+ args = parser.parse_args()
67
+
68
+ detect_qr(args.detect, args.sr, args.image, args.output)
wechat_qr/detect_2026april.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a533c75ec6866759eb28ff8cfb11d30b4887f838124a9ff4ac477e25ad6c7f9f
3
+ size 985788
wechat_qr/example_outputs/input_image.jpg ADDED

Git LFS Details

  • SHA256: 2f58406d668f34286e95bc3e3797beae1e231f15200247deccd6489dbe3c8865
  • Pointer size: 130 Bytes
  • Size of remote file: 52.8 kB
wechat_qr/example_outputs/output_image.png ADDED

Git LFS Details

  • SHA256: a376b21d6702eb6f1b6a714c976ce7659c50d811189be957b04420b157531aa8
  • Pointer size: 131 Bytes
  • Size of remote file: 291 kB
wechat_qr/model_conversion.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import sys
3
+ import os
4
+ import argparse
5
+ import hashlib
6
+
7
+ # Only use sys.path if caffe2onnx isn't installed in your pip/conda env
8
+ sys.path.insert(0, "/path/to/cloned/caffe2onnx")
9
+
10
+ def compute_sha256(filepath):
11
+ """Compute SHA-256 hash of a file for integrity verification."""
12
+ sha256 = hashlib.sha256()
13
+ with open(filepath, "rb") as f:
14
+ for chunk in iter(lambda: f.read(8192), b""):
15
+ sha256.update(chunk)
16
+ return sha256.hexdigest()
17
+
18
+
19
+ def convert_caffe_to_onnx(prototxt, caffemodel, onnx_path):
20
+ """
21
+ Convert a single Caffe model (.prototxt + .caffemodel) to ONNX.
22
+
23
+ Parameters
24
+ ----------
25
+ prototxt : str — path to Caffe .prototxt (network architecture)
26
+ caffemodel : str — path to Caffe .caffemodel (weights)
27
+ onnx_path : str — output .onnx file path
28
+ """
29
+ from caffe2onnx.src.load_save_model import loadcaffemodel, saveonnxmodel
30
+ from caffe2onnx.src.caffe2onnx import Caffe2Onnx
31
+
32
+ assert os.path.isfile(prototxt), "Prototxt not found: {}".format(prototxt)
33
+ assert os.path.isfile(caffemodel), "Caffemodel not found: {}".format(caffemodel)
34
+
35
+ print("Converting: {} -> {}".format(prototxt, onnx_path))
36
+
37
+ graph, params = loadcaffemodel(prototxt, caffemodel)
38
+ converter = Caffe2Onnx(graph, params, onnx_path)
39
+ onnx_model = converter.createOnnxModel()
40
+
41
+ saveonnxmodel(onnx_model, onnx_path)
42
+
43
+ sha = compute_sha256(onnx_path)
44
+ print(" Saved: {} (SHA-256: {})".format(onnx_path, sha))
45
+ return sha
46
+
47
+ MODELS = {
48
+ "detect": ("dnn-models/dnn/wechat_2021-01/detect.prototxt", "dnn-models/dnn/wechat_2021-01/detect.caffemodel"),
49
+ "sr": ("dnn-models/dnn/wechat_2021-01/sr.prototxt", "dnn-models/dnn/wechat_2021-01/sr.caffemodel"),
50
+ }
51
+
52
+
53
+ if __name__ == "__main__":
54
+ parser = argparse.ArgumentParser(
55
+ description="Convert WeChatQR Caffe models to ONNX.")
56
+ parser.add_argument("--input_dir", default=".",
57
+ help="Directory with Caffe model files (default: cwd)")
58
+ parser.add_argument("--output_dir", default=".",
59
+ help="Directory for output ONNX files (default: cwd)")
60
+ args = parser.parse_args()
61
+
62
+ try:
63
+ from caffe2onnx.src.load_save_model import loadcaffemodel, saveonnxmodel
64
+ from caffe2onnx.src.caffe2onnx import Caffe2Onnx
65
+ except ImportError:
66
+ print("Error: caffe2onnx is not installed.")
67
+ print(" pip install caffe2onnx")
68
+ sys.exit(1)
69
+
70
+ os.makedirs(args.output_dir, exist_ok=True)
71
+
72
+ print("=" * 60)
73
+ print("WeChatQR Caffe -> ONNX Conversion")
74
+ print(" Input : {}".format(args.input_dir))
75
+ print(" Output : {}".format(args.output_dir))
76
+ print("=" * 60)
77
+
78
+ for name, (proto_file, caffe_file) in MODELS.items():
79
+ proto_path = os.path.join(args.input_dir, proto_file)
80
+ caffe_path = os.path.join(args.input_dir, caffe_file)
81
+ onnx_path = os.path.join(args.output_dir, name + "_2026april.onnx.onnx")
82
+
83
+ convert_caffe_to_onnx(proto_path, caffe_path, onnx_path)
84
+
85
+ print("=" * 60)
86
+ print("Done.")
wechat_qr/sr_2026april.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:125ab273d59717c5bf4c5dfb674aa9630d3df42e05b99d2d6fa5ffea32fe34f6
3
+ size 26467