Commit c60112e
Update CLIP to a functional model (#2393)
* Refactor CLIP to a functional model
update model input format
update golden values
update CLIP to functional model
update tests
code reformat
use dict instead of list
Update keras_cv/models/feature_extractor/clip/clip_model.py
Co-authored-by: Tirth Patel <[email protected]>
remove build and compute output shape
update model input format
update golden values
Refactor CLIP
Refactor includes:
- CLIPProcessor is now a Keras layer and uses some utilities from KerasNLP to support all types of python types and array inputs
- CLIPImageEncoder, CLIPTextEncoder, and CLIPEncoder now implement a `.compute_output_shape` method (required for CLIP to work with the functional API)
- CLIPHead added to remove raw variables from the CLIP Task models; having variables in `keras.Model` class is tricky since functional API doesn't allow state.
- CLIP checkpointing script has been updated to now work with the new API: new weights will be uploaded to Kaggle.
TODO: attribute KerasNLP wherever relevant
TODO: upload new weights to Kaggle
TODO: refactor the CLIPProcessor class and the CLIP class to also pull tokenizer vocab and merges from Kaggle.
remove build and compute output shape
Some fixes for the refactor
Fix the tests, update presets
update to layers instead of models
* Attempt to fix the Keras 2 error
* remove initializers
* Remove all initializers in ClipAttention
* code reformat
* update initializers
* make this keras 3 only
* update skip test
* add reason for skip
* skipping tests individually :|
* Don't run tests for Keras 2
---------
Co-authored-by: Divyashree Sreepathihalli <divyashreepathihalli>
Co-authored-by: Tirth Patel <[email protected]>1 parent bfeba12 commit c60112e
File tree
10 files changed
+620
-739
lines changed- .kokoro/github/ubuntu/gpu
- keras_cv
- models/feature_extractor/clip
- tools/checkpoint_conversion
10 files changed
+620
-739
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| 87 | + | |
86 | 88 | | |
87 | 89 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | 14 | | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | 19 | | |
36 | 20 | | |
37 | 21 | | |
| |||
54 | 38 | | |
55 | 39 | | |
56 | 40 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | 41 | | |
65 | 42 | | |
66 | 43 | | |
| |||
156 | 133 | | |
157 | 134 | | |
158 | 135 | | |
159 | | - | |
160 | 136 | | |
161 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
162 | 144 | | |
163 | 145 | | |
164 | 146 | | |
| |||
174 | 156 | | |
175 | 157 | | |
176 | 158 | | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | 159 | | |
181 | 160 | | |
182 | 161 | | |
| |||
213 | 192 | | |
214 | 193 | | |
215 | 194 | | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | 195 | | |
223 | 196 | | |
224 | | - | |
225 | 197 | | |
226 | 198 | | |
227 | 199 | | |
228 | 200 | | |
229 | | - | |
230 | 201 | | |
231 | 202 | | |
232 | 203 | | |
233 | 204 | | |
234 | | - | |
235 | 205 | | |
236 | 206 | | |
237 | 207 | | |
238 | 208 | | |
239 | | - | |
240 | 209 | | |
241 | 210 | | |
242 | 211 | | |
| |||
Lines changed: 12 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | | - | |
23 | 21 | | |
24 | 22 | | |
25 | 23 | | |
| |||
33 | 31 | | |
34 | 32 | | |
35 | 33 | | |
36 | | - | |
37 | 34 | | |
38 | 35 | | |
39 | 36 | | |
| |||
42 | 39 | | |
43 | 40 | | |
44 | 41 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | 42 | | |
49 | 43 | | |
50 | 44 | | |
51 | 45 | | |
52 | 46 | | |
53 | 47 | | |
54 | 48 | | |
55 | | - | |
56 | 49 | | |
57 | 50 | | |
58 | 51 | | |
| |||
67 | 60 | | |
68 | 61 | | |
69 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
147 | 146 | | |
148 | 147 | | |
149 | 148 | | |
150 | 149 | | |
151 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
152 | 155 | | |
153 | 156 | | |
154 | 157 | | |
| |||
0 commit comments