Mask Generation
MLX
Safetensors
moonbox
efficientvit
efficientvit-sam
segment-anything
image-segmentation
Instructions to use moonbox-ai/efficientvit-MLX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use moonbox-ai/efficientvit-MLX with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download moonbox-ai/efficientvit-MLX --local-dir efficientvit-MLX
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
Model card and the original license
Browse files
LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright [2023] [Han Cai]
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
README.md
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
pipeline_tag: mask-generation
|
| 4 |
+
library_name: mlx
|
| 5 |
+
tags:
|
| 6 |
+
- mlx
|
| 7 |
+
- moonbox
|
| 8 |
+
- efficientvit
|
| 9 |
+
- efficientvit-sam
|
| 10 |
+
- segment-anything
|
| 11 |
+
- image-segmentation
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# EfficientViT-SAM MLX
|
| 15 |
+
|
| 16 |
+
MLX builds of [EfficientViT-SAM](https://github.com/mit-han-lab/efficientvit), made by Moonbox for Apple Silicon Macs. Each precision is a folder; keep a folder's
|
| 17 |
+
files together. Only the parts listed below are converted: the rest of the pipeline comes from the original
|
| 18 |
+
repository unless the section below says otherwise.
|
| 19 |
+
|
| 20 |
+
## Files
|
| 21 |
+
|
| 22 |
+
The last column is how far each build is from the original PyTorch model on the same inputs (see the section below
|
| 23 |
+
for what was measured).
|
| 24 |
+
|
| 25 |
+
| Precision | File | Size | sha256 | Checked against the original |
|
| 26 |
+
|---|---|---|---|---|
|
| 27 |
+
| fp16 | [`fp16/config.json`](https://huggingface.co/moonbox-ai/efficientvit-MLX/blob/main/fp16/config.json) | 0.3 kB | `9b286f991620` | below threshold (experimental): mask IoU 0.942 mean / 0.611 worst (float32 port: 0.9996 / 0.997) |
|
| 28 |
+
| fp16 | [`fp16/mlx_model.py`](https://huggingface.co/moonbox-ai/efficientvit-MLX/blob/main/fp16/mlx_model.py) | 25.4 kB | `42cea84fb312` | below threshold (experimental): mask IoU 0.942 mean / 0.611 worst (float32 port: 0.9996 / 0.997) |
|
| 29 |
+
| fp16 | [`fp16/model.safetensors`](https://huggingface.co/moonbox-ai/efficientvit-MLX/blob/main/fp16/model.safetensors) | 122.7 MB | `f4b4b159c9f7` | below threshold (experimental): mask IoU 0.942 mean / 0.611 worst (float32 port: 0.9996 / 0.997) |
|
| 30 |
+
|
| 31 |
+
## How to run
|
| 32 |
+
|
| 33 |
+
EfficientViT-SAM **L2** (EfficientViT-L2 image encoder at 512 px + SAM's prompt encoder and mask decoder) ported to
|
| 34 |
+
MLX. Each folder holds `model.safetensors`, `config.json` and `mlx_model.py`, the port (only `mlx`, `numpy` and
|
| 35 |
+
`pillow` needed), with EfficientViTSamPredictor's interface:
|
| 36 |
+
|
| 37 |
+
```python
|
| 38 |
+
import numpy as np, mlx_model
|
| 39 |
+
from PIL import Image
|
| 40 |
+
model = mlx_model.load("fp16")
|
| 41 |
+
rgb = np.array(Image.open("in.jpg").convert("RGB"))
|
| 42 |
+
emb = mlx_model.embed(model, rgb)
|
| 43 |
+
masks, scores, low_res, logits = mlx_model.predict(model, emb, points=[[320, 240]], labels=[1], multimask=True)
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
**Both folders are experimental: this model needs float32.** Thirty of its 1x1 convolutions are followed by a
|
| 47 |
+
BatchNorm with a running variance down to 5.5e-7 (scales up to 600): those channels carry their signal in the 4th-5th
|
| 48 |
+
significant digit of the convolution output, which 16-bit weights or arithmetic can't hold. The port itself is exact:
|
| 49 |
+
run in float32 (with `MLX_ENABLE_TF32=0`, else MLX's float32 matmuls use TF32) it matches PyTorch to mask IoU 0.9996.
|
| 50 |
+
There are no 8bit / 6bit / 4bit folders: quantized, the model gives no usable masks.
|
| 51 |
+
|
| 52 |
+
| Precision | Size | Mask IoU vs PyTorch fp32 (mean / worst) | Status |
|
| 53 |
+
|---|---|---|---|
|
| 54 |
+
| `fp16/` | 122.7 MB | 0.942 / 0.611 | **below threshold (0.95), experimental** |
|
| 55 |
+
| `bf16/` | 122.7 MB | 0.714 / 0.091 | **below threshold, experimental** |
|
| 56 |
+
|
| 57 |
+
To run in float32, load either folder and cast the parameters up (`model.update(mlx.utils.tree_map(lambda a:
|
| 58 |
+
a.astype(mx.float32), model.parameters()))`): fp16 weights in float32 give 0.966 mean / 0.62 worst, still short of
|
| 59 |
+
the original's float32 weights. About 55 ms per image (encoder + 2 prompts) on an Apple M5.
|
| 60 |
+
|
| 61 |
+
## How these were made
|
| 62 |
+
|
| 63 |
+
From [EfficientViT-SAM](https://github.com/mit-han-lab/efficientvit) at revision `de7d7733cc`: the original weights loaded in MLX and stored as bf16 or fp16, or
|
| 64 |
+
quantized with MLX's affine quantization (`8bit`, `6bit`, `4bit`, group size 64; layers MLX can't quantize, such as
|
| 65 |
+
convolutions and norms, stay bf16). Every build was checked against the original before upload; the `sha256` column
|
| 66 |
+
above is what the files must hash to.
|
| 67 |
+
|
| 68 |
+
## License
|
| 69 |
+
|
| 70 |
+
apache-2.0. These files are a derivative of the original model and carry its license: it is copied in this
|
| 71 |
+
repository, and it governs your use of these files. The original model card follows unchanged.
|
| 72 |
+
|
| 73 |
+
---
|
| 74 |
+
|
| 75 |
+
# Original model card
|
| 76 |
+
|
| 77 |
+
# Efficient Vision Foundation Models for High-Resolution Generation and Perception
|
| 78 |
+
|
| 79 |
+
[](https://paperswithcode.com/sota/image-generation-on-imagenet-512x512?p=deep-compression-autoencoder-for-efficient)
|
| 80 |
+
|
| 81 |
+
## News
|
| 82 |
+
- (🔥 New) [2025/09/05] We will no longer maintain this codebase. All future updates and announcements will be made on [DC-Gen](https://github.com/dc-ai-projects/DC-Gen).
|
| 83 |
+
- (🔥 New) [2025/01/24] We released DC-AE-SANA-1.1: [doc](https://github.com/mit-han-lab/efficientvit/blob/master/assets/docs/dc_ae_sana_1.1.md).
|
| 84 |
+
- (🔥 New) [2025/01/23] DC-AE and SANA are accepted by ICLR 2025.
|
| 85 |
+
- (🔥 New) [2025/01/14] We released **DC-AE+USiT models**: [model](https://huggingface.co/collections/mit-han-lab/dc-ae-diffusion-670dbb8d6b6914cf24c1a49d), [training](https://github.com/mit-han-lab/efficientvit/blob/master/applications/dc_ae/README.md#dc-ae--usit). Using the default training settings and sampling strategy, DC-AE+USiT-2B achieves 1.72 FID on ImageNet 512x512, surpassing the SOTA diffusion model EDM2-XXL and SOTA auto-regressive image generative models (MAGVIT-v2 and MAR-L).
|
| 86 |
+
|
| 87 |
+
______________________________________________________________________
|
| 88 |
+
|
| 89 |
+
- (🔥 New) [2024/12/24] **diffusers** supports DC-AE models. All [DC-AE models in diffusers safetensors](https://huggingface.co/collections/mit-han-lab/dc-ae-670085b9400ad7197bb1009b) are released. [Usage](https://github.com/mit-han-lab/efficientvit/tree/master/applications/dc_ae#deep-compression-autoencoder-diffusers).
|
| 90 |
+
- [2024/10/21] DC-AE and EfficientViT block are used in our latest text-to-image diffusion model SANA! Check the [project page](https://nvlabs.github.io/Sana/) for more details.
|
| 91 |
+
- [2024/10/15] We released **Deep Compression Autoencoder (DC-AE)**: [link](#deep-compression-autoencoder-for-efficient-high-resolution-diffusion-models-paper-readme)!
|
| 92 |
+
- [2024/07/10] EfficientViT is used as the backbone in [Grounding DINO 1.5 Edge](https://arxiv.org/pdf/2405.10300) for efficient open-set object detection.
|
| 93 |
+
- [2024/07/10] EfficientViT-SAM is used in [MedficientSAM](https://github.com/hieplpvip/medficientsam), the 1st place model in [CVPR 2024 Segment Anything In Medical Images On Laptop Challenge](https://www.codabench.org/competitions/1847/).
|
| 94 |
+
- [2024/04/06] EfficientViT-SAM is accepted by [eLVM@CVPR'24](https://sites.google.com/view/elvm/home?authuser=0).
|
| 95 |
+
- [2024/03/19] Online demo of EfficientViT-SAM is available: [https://evitsam.hanlab.ai/](https://evitsam.hanlab.ai/).
|
| 96 |
+
- [2024/02/07] We released [EfficientViT-SAM](https://arxiv.org/abs/2402.05008), the first accelerated SAM model that matches/outperforms SAM-ViT-H's zero-shot performance, delivering the SOTA performance-efficiency trade-off.
|
| 97 |
+
- [2023/11/20] EfficientViT is available in the [NVIDIA Jetson Generative AI Lab](https://www.jetson-ai-lab.com/tutorial_efficientvit.html).
|
| 98 |
+
- [2023/09/12] EfficientViT is highlighted by [MIT home page](https://www.mit.edu/archive/spotlight/efficient-computer-vision/) and [MIT News](https://news.mit.edu/2023/ai-model-high-resolution-computer-vision-0912).
|
| 99 |
+
- [2023/07/18] EfficientViT is accepted by ICCV 2023.
|
| 100 |
+
|
| 101 |
+
## Content
|
| 102 |
+
|
| 103 |
+
### [ICLR 2025] Deep Compression Autoencoder for Efficient High-Resolution Diffusion Models [[paper](https://arxiv.org/abs/2410.10733)] [[readme](applications/dc_ae/README.md)] [[poster](assets/dc_ae_poster.pdf)]
|
| 104 |
+
|
| 105 |
+
**Deep Compression Autoencoder (DC-AE) is a new family of high-spatial compression autoencoders with a spatial compression ratio of up to 128 while maintaining reconstruction quality. It accelerates all latent diffusion models regardless of the diffusion model architecture.**
|
| 106 |
+
|
| 107 |
+
#### Demo
|
| 108 |
+
|
| 109 |
+

|
| 110 |
+
<p align="center">
|
| 111 |
+
<b> Figure 1: We address the reconstruction accuracy drop of high spatial-compression autoencoders.
|
| 112 |
+
</p>
|
| 113 |
+
|
| 114 |
+

|
| 115 |
+
<p align="center">
|
| 116 |
+
<b> Figure 2: DC-AE speeds up latent diffusion models.
|
| 117 |
+
</p>
|
| 118 |
+
|
| 119 |
+
<p align="center">
|
| 120 |
+
<img src="https://huggingface.co/mit-han-lab/dc-ae-f64c128-in-1.0/resolve/main/assets/dc_ae_sana.jpg" width="1200">
|
| 121 |
+
</p>
|
| 122 |
+
|
| 123 |
+
<p align="center">
|
| 124 |
+
<b> Figure 3: DC-AE enables efficient text-to-image generation on the laptop: <a href="https://nvlabs.github.io/Sana/">SANA</a>.
|
| 125 |
+
</p>
|
| 126 |
+
|
| 127 |
+
- [Usage of Deep Compression Autoencoder](applications/dc_ae/README.md#deep-compression-autoencoder)
|
| 128 |
+
- [Usage of DC-AE-Diffusion](applications/dc_ae/README.md#efficient-diffusion-models-with-dc-ae)
|
| 129 |
+
- [Evaluate Deep Compression Autoencoder](applications/dc_ae/README.md#evaluate-deep-compression-autoencoder)
|
| 130 |
+
- [Demo DC-AE-Diffusion Models](applications/dc_ae/README.md#demo-dc-ae-diffusion-models)
|
| 131 |
+
- [Evaluate DC-AE-Diffusion Models](applications/dc_ae/README.md#evaluate-dc-ae-diffusion-models)
|
| 132 |
+
- [Train DC-AE-Diffusion Models](applications/dc_ae/README.md#train-dc-ae-diffusion-models)
|
| 133 |
+
- [Reference](applications/dc_ae/README.md#reference)
|
| 134 |
+
|
| 135 |
+
### [CVPR 2024 eLVM Workshop] EfficientViT-SAM: Accelerated Segment Anything Model Without Accuracy Loss [[paper](https://arxiv.org/abs/2402.05008)] [[online demo](https://evitsam.hanlab.ai/)] [[readme](applications/efficientvit_sam/README.md)]
|
| 136 |
+
|
| 137 |
+
**EfficientViT-SAM is a new family of accelerated segment anything models by replacing SAM's heavy image encoder with EfficientViT. It delivers a 48.9x measured TensorRT speedup on A100 GPU over SAM-ViT-H without sacrificing accuracy.**
|
| 138 |
+
|
| 139 |
+
<p align="left">
|
| 140 |
+
<img src="https://huggingface.co/mit-han-lab/efficientvit-sam/resolve/main/sam_zero_shot_coco_mAP.png" width="500">
|
| 141 |
+
</p>
|
| 142 |
+
|
| 143 |
+
- [Pretrained EfficientViT-SAM Models](applications/efficientvit_sam/README.md#pretrained-efficientvit-sam-models)
|
| 144 |
+
- [Usage of EfficientViT-SAM](applications/efficientvit_sam/README.md#usage)
|
| 145 |
+
- [Evaluate EfficientViT-SAM](applications/efficientvit_sam/README.md#evaluation)
|
| 146 |
+
- [Visualize EfficientViT-SAM](applications/efficientvit_sam/README.md#visualization)
|
| 147 |
+
- [Deploy EfficientViT-SAM](applications/efficientvit_sam/README.md#deployment)
|
| 148 |
+
- [Train EfficientViT-SAM](applications/efficientvit_sam/README.md#training)
|
| 149 |
+
- [Reference](applications/efficientvit_sam/README.md#reference)
|
| 150 |
+
|
| 151 |
+
### [ICCV 2023] EfficientViT-Classification [[paper](https://arxiv.org/abs/2205.14756)] [[readme](applications/efficientvit_cls/README.md)]
|
| 152 |
+
|
| 153 |
+
**Efficient image classification models with EfficientViT backbones.**
|
| 154 |
+
|
| 155 |
+
<p align="left">
|
| 156 |
+
<img src="https://huggingface.co/han-cai/efficientvit-cls/resolve/main/efficientvit_cls_results.png" width="600">
|
| 157 |
+
</p>
|
| 158 |
+
|
| 159 |
+
- [Pretrained EfficientViT Classification Models](applications/efficientvit_cls/README.md#pretrained-efficientvit-classification-models)
|
| 160 |
+
- [Usage of EfficientViT Classification Models](applications/efficientvit_cls/README.md#usage)
|
| 161 |
+
- [Evaluate EfficientViT Classification Models](applications/efficientvit_cls/README.md#evaluation)
|
| 162 |
+
- [Export EfficientViT Classification Models](applications/efficientvit_cls/README.md#export)
|
| 163 |
+
- [Train EfficientViT Classification Models](applications/efficientvit_cls/README.md#training)
|
| 164 |
+
- [Reference](applications/efficientvit_cls/README.md#reference)
|
| 165 |
+
|
| 166 |
+
### [ICCV 2023] EfficientViT-Segmentation [[paper](https://arxiv.org/abs/2205.14756)] [[readme](applications/efficientvit_seg/README.md)]
|
| 167 |
+
|
| 168 |
+
**Efficient semantic segmantation models with EfficientViT backbones.**
|
| 169 |
+
|
| 170 |
+

|
| 171 |
+
|
| 172 |
+
- [Pretrained EfficientViT Segmentation Models](applications/efficientvit_seg/README.md#pretrained-efficientvit-segmentation-models)
|
| 173 |
+
- [Usage of EfficientViT Segmentation Models](applications/efficientvit_seg/README.md#usage)
|
| 174 |
+
- [Evaluate EfficientViT Segmentation Models](applications/efficientvit_seg/README.md#evaluation)
|
| 175 |
+
- [Visualize EfficientViT Segmentation Models](applications/efficientvit_seg/README.md#visualization)
|
| 176 |
+
- [Export EfficientViT Segmentation Models](applications/efficientvit_seg/README.md#export)
|
| 177 |
+
- [Reference](applications/efficientvit_seg/README.md#reference)
|
| 178 |
+
|
| 179 |
+
### EfficientViT-GazeSAM [[readme](applications/efficientvit_gazesam/README.md)]
|
| 180 |
+
|
| 181 |
+
**Gaze-prompted image segmentation models capable of running in real time with TensorRT on an NVIDIA RTX 4070.**
|
| 182 |
+
|
| 183 |
+

|
| 184 |
+
|
| 185 |
+
## Getting Started
|
| 186 |
+
|
| 187 |
+
```bash
|
| 188 |
+
conda create -n efficientvit python=3.10
|
| 189 |
+
conda activate efficientvit
|
| 190 |
+
pip install -U -r requirements.txt
|
| 191 |
+
```
|
| 192 |
+
|
| 193 |
+
## Third-Party Implementation/Integration
|
| 194 |
+
|
| 195 |
+
- [NVIDIA Jetson Generative AI Lab](https://www.jetson-ai-lab.com/tutorial_efficientvit.html)
|
| 196 |
+
- [timm](https://github.com/huggingface/pytorch-image-models): [link](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/efficientvit_mit.py)
|
| 197 |
+
- [X-AnyLabeling](https://github.com/CVHub520/X-AnyLabeling): [link](https://github.com/CVHub520/X-AnyLabeling/blob/main/anylabeling/services/auto_labeling/efficientvit_sam.py)
|
| 198 |
+
- [Grounding DINO 1.5 Edge](https://github.com/IDEA-Research/Grounding-DINO-1.5-API): [link](https://arxiv.org/pdf/2405.10300)
|
| 199 |
+
|
| 200 |
+
## Contact
|
| 201 |
+
|
| 202 |
+
[Han Cai](http://hancai.ai/)
|
| 203 |
+
|
| 204 |
+
## Reference
|
| 205 |
+
|
| 206 |
+
If EfficientViT or EfficientViT-SAM or DC-AE is useful or relevant to your research, please kindly recognize our contributions by citing our paper:
|
| 207 |
+
|
| 208 |
+
```bibtex
|
| 209 |
+
@inproceedings{cai2023efficientvit,
|
| 210 |
+
title={Efficientvit: Lightweight multi-scale attention for high-resolution dense prediction},
|
| 211 |
+
author={Cai, Han and Li, Junyan and Hu, Muyan and Gan, Chuang and Han, Song},
|
| 212 |
+
booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
|
| 213 |
+
pages={17302--17313},
|
| 214 |
+
year={2023}
|
| 215 |
+
}
|
| 216 |
+
```
|
| 217 |
+
|
| 218 |
+
```bibtex
|
| 219 |
+
@article{zhang2024efficientvit,
|
| 220 |
+
title={EfficientViT-SAM: Accelerated Segment Anything Model Without Performance Loss},
|
| 221 |
+
author={Zhang, Zhuoyang and Cai, Han and Han, Song},
|
| 222 |
+
journal={arXiv preprint arXiv:2402.05008},
|
| 223 |
+
year={2024}
|
| 224 |
+
}
|
| 225 |
+
```
|
| 226 |
+
|
| 227 |
+
```bibtex
|
| 228 |
+
@article{chen2024deep,
|
| 229 |
+
title={Deep Compression Autoencoder for Efficient High-Resolution Diffusion Models},
|
| 230 |
+
author={Chen, Junyu and Cai, Han and Chen, Junsong and Xie, Enze and Yang, Shang and Tang, Haotian and Li, Muyang and Lu, Yao and Han, Song},
|
| 231 |
+
journal={arXiv preprint arXiv:2410.10733},
|
| 232 |
+
year={2024}
|
| 233 |
+
}
|
| 234 |
+
```
|