Upload sd_token_similarity_calculator.ipynb
Browse files- sd_token_similarity_calculator.ipynb +445 -840
sd_token_similarity_calculator.ipynb
CHANGED
@@ -123,7 +123,7 @@
|
|
123 |
],
|
124 |
"metadata": {
|
125 |
"id": "rUXQ73IbonHY",
|
126 |
-
"outputId": "
|
127 |
"colab": {
|
128 |
"base_uri": "https://localhost:8080/"
|
129 |
}
|
@@ -136,13 +136,13 @@
|
|
136 |
"text": [
|
137 |
"/content\n",
|
138 |
"Cloning into 'text-to-image-prompts'...\n",
|
139 |
-
"remote: Enumerating objects:
|
140 |
-
"remote: Counting objects: 100% (
|
141 |
-
"remote: Compressing objects: 100% (
|
142 |
-
"remote: Total
|
143 |
-
"Receiving objects: 100% (
|
144 |
-
"Resolving deltas: 100% (
|
145 |
-
"Filtering content: 100% (95/95), 305.98 MiB |
|
146 |
]
|
147 |
}
|
148 |
]
|
@@ -223,258 +223,10 @@
|
|
223 |
"NUM_VOCAB_ITEMS = nA\n"
|
224 |
],
|
225 |
"metadata": {
|
226 |
-
"id": "ZMG4CThUAmwW"
|
227 |
-
"outputId": "029abb8c-ccb0-40af-b87c-df6e61d7548a",
|
228 |
-
"colab": {
|
229 |
-
"base_uri": "https://localhost:8080/"
|
230 |
-
}
|
231 |
},
|
232 |
"execution_count": null,
|
233 |
-
"outputs": [
|
234 |
-
{
|
235 |
-
"output_type": "stream",
|
236 |
-
"name": "stdout",
|
237 |
-
"text": [
|
238 |
-
"reading 🦜 fusion-t2i-prompt-features-23.json....\n",
|
239 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
240 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
241 |
-
"reading 🦜 fusion-t2i-prompt-features-9.json....\n",
|
242 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
243 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
244 |
-
"reading 🦜 fusion-t2i-prompt-features-4.json....\n",
|
245 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
246 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
247 |
-
"reading 🦜 fusion-t2i-prompt-features-2.json....\n",
|
248 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
249 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
250 |
-
"reading 🦜 fusion-t2i-prompt-features-25.json....\n",
|
251 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
252 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
253 |
-
"reading 🦜 fusion-t2i-prompt-features-6.json....\n",
|
254 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
255 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
256 |
-
"reading 🦜 fusion-t2i-prompt-features-19.json....\n",
|
257 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
258 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
259 |
-
"reading 🦜 fusion-t2i-prompt-features-33.json....\n",
|
260 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
261 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
262 |
-
"reading 🦜 fusion-t2i-prompt-features-18.json....\n",
|
263 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
264 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
265 |
-
"reading 🦜 fusion-t2i-prompt-features-22.json....\n",
|
266 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
267 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
268 |
-
"reading 🦜 fusion-t2i-prompt-features-31.json....\n",
|
269 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
270 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
271 |
-
"reading 🦜 fusion-t2i-prompt-features-3.json....\n",
|
272 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
273 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
274 |
-
"reading 🦜 fusion-t2i-prompt-features-8.json....\n",
|
275 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
276 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
277 |
-
"reading 🦜 fusion-t2i-prompt-features-7.json....\n",
|
278 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
279 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
280 |
-
"reading 🦜 fusion-t2i-prompt-features-13.json....\n",
|
281 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
282 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
283 |
-
"reading 🦜 fusion-t2i-prompt-features-34.json....\n",
|
284 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
285 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
286 |
-
"reading 🦜 fusion-t2i-prompt-features-14.json....\n",
|
287 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
288 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
289 |
-
"reading 🦜 fusion-t2i-prompt-features-12.json....\n",
|
290 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
291 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
292 |
-
"reading 🦜 fusion-t2i-prompt-features-17.json....\n",
|
293 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
294 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
295 |
-
"reading 🦜 fusion-t2i-prompt-features-21.json....\n",
|
296 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
297 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
298 |
-
"reading 🦜 fusion-t2i-prompt-features-24.json....\n",
|
299 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
300 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
301 |
-
"reading 🦜 fusion-t2i-prompt-features-32.json....\n",
|
302 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
303 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
304 |
-
"reading 🦜 fusion-t2i-prompt-features-5.json....\n",
|
305 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
306 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
307 |
-
"reading 🦜 fusion-t2i-prompt-features-20.json....\n",
|
308 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
309 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
310 |
-
"reading 🦜 fusion-t2i-prompt-features-16.json....\n",
|
311 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
312 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
313 |
-
"reading 🦜 fusion-t2i-prompt-features-28.json....\n",
|
314 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
315 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
316 |
-
"reading 🦜 fusion-t2i-prompt-features-10.json....\n",
|
317 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
318 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
319 |
-
"reading 🦜 fusion-t2i-prompt-features-15.json....\n",
|
320 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
321 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
322 |
-
"reading 🦜 fusion-t2i-prompt-features-26.json....\n",
|
323 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
324 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
325 |
-
"reading 🦜 fusion-t2i-prompt-features-27.json....\n",
|
326 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
327 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
328 |
-
"reading 🦜 fusion-t2i-prompt-features-1.json....\n",
|
329 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
330 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
331 |
-
"reading 🦜 fusion-t2i-prompt-features-29.json....\n",
|
332 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
333 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
334 |
-
"reading 🦜 fusion-t2i-prompt-features-30.json....\n",
|
335 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
336 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
337 |
-
"reading 🦜 fusion-t2i-prompt-features-11.json....\n",
|
338 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text\n",
|
339 |
-
"/content/text-to-image-prompts/civitai-prompts/green/text_encodings\n",
|
340 |
-
"reading 😃 fusion-t2i-emojis-2.json....\n",
|
341 |
-
"/content/text-to-image-prompts/tokens/emoji/text\n",
|
342 |
-
"/content/text-to-image-prompts/tokens/emoji/text_encodings\n",
|
343 |
-
"reading 🧿📘 fusion-t2i-civitai-0-20-chars-mix-2.json....\n",
|
344 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text\n",
|
345 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text_encodings\n",
|
346 |
-
"reading 🧿📘 fusion-t2i-civitai-0-20-chars-mix-10.json....\n",
|
347 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text\n",
|
348 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text_encodings\n",
|
349 |
-
"reading 🧿📘 fusion-t2i-civitai-0-20-chars-mix-6.json....\n",
|
350 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text\n",
|
351 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text_encodings\n",
|
352 |
-
"reading 🧿📘 fusion-t2i-civitai-0-20-chars-mix-5.json....\n",
|
353 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text\n",
|
354 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text_encodings\n",
|
355 |
-
"reading 🧿📘 fusion-t2i-civitai-0-20-chars-mix-4.json....\n",
|
356 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text\n",
|
357 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text_encodings\n",
|
358 |
-
"reading 🧿📘 fusion-t2i-civitai-0-20-chars-mix-8.json....\n",
|
359 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text\n",
|
360 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text_encodings\n",
|
361 |
-
"reading 🧿📘 fusion-t2i-civitai-0-20-chars-mix-1.json....\n",
|
362 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text\n",
|
363 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text_encodings\n",
|
364 |
-
"reading 🧿📘 fusion-t2i-civitai-0-20-chars-mix-7.json....\n",
|
365 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text\n",
|
366 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text_encodings\n",
|
367 |
-
"reading 🧿📘 fusion-t2i-civitai-0-20-chars-mix-3.json....\n",
|
368 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text\n",
|
369 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text_encodings\n",
|
370 |
-
"reading 🧿📘 fusion-t2i-civitai-0-20-chars-mix-9.json....\n",
|
371 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text\n",
|
372 |
-
"/content/text-to-image-prompts/civitai-prompts/blue/text_encodings\n",
|
373 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-common-suffix-5 Tokens.json....\n",
|
374 |
-
"/content/text-to-image-prompts/tokens/suffix/common/text\n",
|
375 |
-
"/content/text-to-image-prompts/tokens/suffix/common/text_encodings\n",
|
376 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-common-suffix-2 Tokens.json....\n",
|
377 |
-
"/content/text-to-image-prompts/tokens/suffix/common/text\n",
|
378 |
-
"/content/text-to-image-prompts/tokens/suffix/common/text_encodings\n",
|
379 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-common-suffix-3 Tokens.json....\n",
|
380 |
-
"/content/text-to-image-prompts/tokens/suffix/common/text\n",
|
381 |
-
"/content/text-to-image-prompts/tokens/suffix/common/text_encodings\n",
|
382 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-common-suffix-4 Tokens.json....\n",
|
383 |
-
"/content/text-to-image-prompts/tokens/suffix/common/text\n",
|
384 |
-
"/content/text-to-image-prompts/tokens/suffix/common/text_encodings\n",
|
385 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-common-suffix-1 Tokens.json....\n",
|
386 |
-
"/content/text-to-image-prompts/tokens/suffix/common/text\n",
|
387 |
-
"/content/text-to-image-prompts/tokens/suffix/common/text_encodings\n",
|
388 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-common-suffix-6 Tokens.json....\n",
|
389 |
-
"/content/text-to-image-prompts/tokens/suffix/common/text\n",
|
390 |
-
"/content/text-to-image-prompts/tokens/suffix/common/text_encodings\n",
|
391 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-average-suffix-5 Tokens.json....\n",
|
392 |
-
"/content/text-to-image-prompts/tokens/suffix/average/text\n",
|
393 |
-
"/content/text-to-image-prompts/tokens/suffix/average/text_encodings\n",
|
394 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-average-suffix-1 Tokens.json....\n",
|
395 |
-
"/content/text-to-image-prompts/tokens/suffix/average/text\n",
|
396 |
-
"/content/text-to-image-prompts/tokens/suffix/average/text_encodings\n",
|
397 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-average-suffix-6 Tokens.json....\n",
|
398 |
-
"/content/text-to-image-prompts/tokens/suffix/average/text\n",
|
399 |
-
"/content/text-to-image-prompts/tokens/suffix/average/text_encodings\n",
|
400 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-average-suffix-2 Tokens.json....\n",
|
401 |
-
"/content/text-to-image-prompts/tokens/suffix/average/text\n",
|
402 |
-
"/content/text-to-image-prompts/tokens/suffix/average/text_encodings\n",
|
403 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-average-suffix-3 Tokens.json....\n",
|
404 |
-
"/content/text-to-image-prompts/tokens/suffix/average/text\n",
|
405 |
-
"/content/text-to-image-prompts/tokens/suffix/average/text_encodings\n",
|
406 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-average-suffix-7 Tokens.json....\n",
|
407 |
-
"/content/text-to-image-prompts/tokens/suffix/average/text\n",
|
408 |
-
"/content/text-to-image-prompts/tokens/suffix/average/text_encodings\n",
|
409 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-average-suffix-4 Tokens.json....\n",
|
410 |
-
"/content/text-to-image-prompts/tokens/suffix/average/text\n",
|
411 |
-
"/content/text-to-image-prompts/tokens/suffix/average/text_encodings\n",
|
412 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-rare-suffix-6 Tokens.json....\n",
|
413 |
-
"/content/text-to-image-prompts/tokens/suffix/rare/text\n",
|
414 |
-
"/content/text-to-image-prompts/tokens/suffix/rare/text_encodings\n",
|
415 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-rare-suffix-1 Tokens.json....\n",
|
416 |
-
"/content/text-to-image-prompts/tokens/suffix/rare/text\n",
|
417 |
-
"/content/text-to-image-prompts/tokens/suffix/rare/text_encodings\n",
|
418 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-rare-suffix-5 Tokens.json....\n",
|
419 |
-
"/content/text-to-image-prompts/tokens/suffix/rare/text\n",
|
420 |
-
"/content/text-to-image-prompts/tokens/suffix/rare/text_encodings\n",
|
421 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-rare-suffix-2 Tokens.json....\n",
|
422 |
-
"/content/text-to-image-prompts/tokens/suffix/rare/text\n",
|
423 |
-
"/content/text-to-image-prompts/tokens/suffix/rare/text_encodings\n",
|
424 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-rare-suffix-7 Tokens.json....\n",
|
425 |
-
"/content/text-to-image-prompts/tokens/suffix/rare/text\n",
|
426 |
-
"/content/text-to-image-prompts/tokens/suffix/rare/text_encodings\n",
|
427 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-rare-suffix-3 Tokens.json....\n",
|
428 |
-
"/content/text-to-image-prompts/tokens/suffix/rare/text\n",
|
429 |
-
"/content/text-to-image-prompts/tokens/suffix/rare/text_encodings\n",
|
430 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-rare-suffix-4 Tokens.json....\n",
|
431 |
-
"/content/text-to-image-prompts/tokens/suffix/rare/text\n",
|
432 |
-
"/content/text-to-image-prompts/tokens/suffix/rare/text_encodings\n",
|
433 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-weird-suffix-6 Tokens.json....\n",
|
434 |
-
"/content/text-to-image-prompts/tokens/suffix/weird/text\n",
|
435 |
-
"/content/text-to-image-prompts/tokens/suffix/weird/text_encodings\n",
|
436 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-weird-suffix-3 Tokens.json....\n",
|
437 |
-
"/content/text-to-image-prompts/tokens/suffix/weird/text\n",
|
438 |
-
"/content/text-to-image-prompts/tokens/suffix/weird/text_encodings\n",
|
439 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-weird-suffix-5 Tokens.json....\n",
|
440 |
-
"/content/text-to-image-prompts/tokens/suffix/weird/text\n",
|
441 |
-
"/content/text-to-image-prompts/tokens/suffix/weird/text_encodings\n",
|
442 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-weird-suffix-1 Tokens.json....\n",
|
443 |
-
"/content/text-to-image-prompts/tokens/suffix/weird/text\n",
|
444 |
-
"/content/text-to-image-prompts/tokens/suffix/weird/text_encodings\n",
|
445 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-weird-suffix-4 Tokens.json....\n",
|
446 |
-
"/content/text-to-image-prompts/tokens/suffix/weird/text\n",
|
447 |
-
"/content/text-to-image-prompts/tokens/suffix/weird/text_encodings\n",
|
448 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-weird-suffix-2 Tokens.json....\n",
|
449 |
-
"/content/text-to-image-prompts/tokens/suffix/weird/text\n",
|
450 |
-
"/content/text-to-image-prompts/tokens/suffix/weird/text_encodings\n",
|
451 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-weird-suffix-7 Tokens.json....\n",
|
452 |
-
"/content/text-to-image-prompts/tokens/suffix/weird/text\n",
|
453 |
-
"/content/text-to-image-prompts/tokens/suffix/weird/text_encodings\n",
|
454 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-exotic-suffix-4 Tokens.json....\n",
|
455 |
-
"/content/text-to-image-prompts/tokens/suffix/exotic/text\n",
|
456 |
-
"/content/text-to-image-prompts/tokens/suffix/exotic/text_encodings\n",
|
457 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-exotic-suffix-2 Tokens.json....\n",
|
458 |
-
"/content/text-to-image-prompts/tokens/suffix/exotic/text\n",
|
459 |
-
"/content/text-to-image-prompts/tokens/suffix/exotic/text_encodings\n",
|
460 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-exotic-suffix-3 Tokens.json....\n",
|
461 |
-
"/content/text-to-image-prompts/tokens/suffix/exotic/text\n",
|
462 |
-
"/content/text-to-image-prompts/tokens/suffix/exotic/text_encodings\n",
|
463 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-exotic-suffix-1 Tokens.json....\n",
|
464 |
-
"/content/text-to-image-prompts/tokens/suffix/exotic/text\n",
|
465 |
-
"/content/text-to-image-prompts/tokens/suffix/exotic/text_encodings\n",
|
466 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-exotic-suffix-7 Tokens.json....\n",
|
467 |
-
"/content/text-to-image-prompts/tokens/suffix/exotic/text\n",
|
468 |
-
"/content/text-to-image-prompts/tokens/suffix/exotic/text_encodings\n",
|
469 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-exotic-suffix-6 Tokens.json....\n",
|
470 |
-
"/content/text-to-image-prompts/tokens/suffix/exotic/text\n",
|
471 |
-
"/content/text-to-image-prompts/tokens/suffix/exotic/text_encodings\n",
|
472 |
-
"reading 🔹 fusion-t2i-sd15-clip-tokens-exotic-suffix-5 Tokens.json....\n",
|
473 |
-
"/content/text-to-image-prompts/tokens/suffix/exotic/text\n",
|
474 |
-
"/content/text-to-image-prompts/tokens/suffix/exotic/text_encodings\n"
|
475 |
-
]
|
476 |
-
}
|
477 |
-
]
|
478 |
},
|
479 |
{
|
480 |
"cell_type": "code",
|
@@ -555,121 +307,10 @@
|
|
555 |
"#-------#"
|
556 |
],
|
557 |
"metadata": {
|
558 |
-
"id": "_vnVbxcFf7WV"
|
559 |
-
"outputId": "1c8953a9-6519-4b6a-cb45-127d34beaddf",
|
560 |
-
"colab": {
|
561 |
-
"base_uri": "https://localhost:8080/"
|
562 |
-
}
|
563 |
},
|
564 |
"execution_count": null,
|
565 |
-
"outputs": [
|
566 |
-
{
|
567 |
-
"output_type": "stream",
|
568 |
-
"name": "stdout",
|
569 |
-
"text": [
|
570 |
-
"{Sports Car|\n",
|
571 |
-
"beautiful car|\n",
|
572 |
-
"her car behind on the road|\n",
|
573 |
-
"the race car driver sits behind the wheel|\n",
|
574 |
-
"racing car in the background|\n",
|
575 |
-
"road nature|\n",
|
576 |
-
"running road|\n",
|
577 |
-
"sport car petite|\n",
|
578 |
-
"it's a gas gas|\n",
|
579 |
-
"The Road Not Taken|\n",
|
580 |
-
"cyber car looking_upscenery|\n",
|
581 |
-
"cyber car looking_upscenery|\n",
|
582 |
-
"road Horizon|\n",
|
583 |
-
"a beautiful|\n",
|
584 |
-
"a beautiful|\n",
|
585 |
-
"far away|\n",
|
586 |
-
"speed</w>|\n",
|
587 |
-
"roadtrip</w>|\n",
|
588 |
-
"driving</w>|\n",
|
589 |
-
"true to life|\n",
|
590 |
-
"street|\n",
|
591 |
-
"ontheroad</w>|\n",
|
592 |
-
"sharp image|\n",
|
593 |
-
"on a race track|\n",
|
594 |
-
"road construction|\n",
|
595 |
-
"with a soft|\n",
|
596 |
-
"on the crowded streets|\n",
|
597 |
-
"a picture|\n",
|
598 |
-
"faster</w>|\n",
|
599 |
-
"Fantastic|\n",
|
600 |
-
"loving|\n",
|
601 |
-
"the image should have|\n",
|
602 |
-
"takes off down the track|\n",
|
603 |
-
"road architecture|\n",
|
604 |
-
"and you can't help but feel|\n",
|
605 |
-
"day scenery|\n",
|
606 |
-
"wonderful|\n",
|
607 |
-
"but now seems to exude|\n",
|
608 |
-
"is appropriate for the time period|\n",
|
609 |
-
"head back|\n",
|
610 |
-
"photographic style|\n",
|
611 |
-
"very sweet|\n",
|
612 |
-
"alright</w>|\n",
|
613 |
-
"thats</w>|\n",
|
614 |
-
"awesome inspiring|\n",
|
615 |
-
"Know the past|\n",
|
616 |
-
"seems</w>|\n",
|
617 |
-
"as style|\n",
|
618 |
-
"inspired|\n",
|
619 |
-
"should have an attentive|\n",
|
620 |
-
"the image should be one|\n",
|
621 |
-
"lovely|\n",
|
622 |
-
"well</w>|\n",
|
623 |
-
"reminds</w>|\n",
|
624 |
-
"looking pass the came|\n",
|
625 |
-
"looking pass the came|\n",
|
626 |
-
"beautiful amazing|\n",
|
627 |
-
"highway</w>|\n",
|
628 |
-
"appears timeless|\n",
|
629 |
-
"emphasizing the sense|\n",
|
630 |
-
"that</w>|\n",
|
631 |
-
"beautiful gorgeous|\n",
|
632 |
-
"highway setting|\n",
|
633 |
-
"science fiction|\n",
|
634 |
-
"Science fiction|\n",
|
635 |
-
"speeding</w>|\n",
|
636 |
-
"an engine or the clanking|\n",
|
637 |
-
"in a mountain land|\n",
|
638 |
-
"inspiration|\n",
|
639 |
-
"day time|\n",
|
640 |
-
"beautiful_|\n",
|
641 |
-
"busy highway|\n",
|
642 |
-
"really</w>|\n",
|
643 |
-
"sitting in the driver seat|\n",
|
644 |
-
"bright the image should convey|\n",
|
645 |
-
"Phenomenal|\n",
|
646 |
-
"girl trembling|\n",
|
647 |
-
"inspired by the last|\n",
|
648 |
-
"beauty|\n",
|
649 |
-
"advanced technology in|\n",
|
650 |
-
"baby|\n",
|
651 |
-
"adding to the overall sense|\n",
|
652 |
-
"top quality|\n",
|
653 |
-
"motorcycle freeway|\n",
|
654 |
-
"very beautiful|\n",
|
655 |
-
"beautiful beautiful|\n",
|
656 |
-
"cute beautiful|\n",
|
657 |
-
"Beautiful|\n",
|
658 |
-
"beautiful|\n",
|
659 |
-
"beautiful|\n",
|
660 |
-
"best highest quallity|\n",
|
661 |
-
"meticulous attention to|\n",
|
662 |
-
"meticulous attention to|\n",
|
663 |
-
"tweeted</w>|\n",
|
664 |
-
"street in city|\n",
|
665 |
-
"a gorgeous|\n",
|
666 |
-
"exciting|\n",
|
667 |
-
"a beautiful ravishing|\n",
|
668 |
-
"fire flames|\n",
|
669 |
-
"police car in background}\n"
|
670 |
-
]
|
671 |
-
}
|
672 |
-
]
|
673 |
},
|
674 |
{
|
675 |
"cell_type": "markdown",
|
@@ -825,121 +466,10 @@
|
|
825 |
"#-------#"
|
826 |
],
|
827 |
"metadata": {
|
828 |
-
"id": "JkzncP8SgKtS"
|
829 |
-
"colab": {
|
830 |
-
"base_uri": "https://localhost:8080/"
|
831 |
-
},
|
832 |
-
"outputId": "2271de2f-6885-4f72-bcd0-3c39a9cfaada"
|
833 |
},
|
834 |
"execution_count": null,
|
835 |
-
"outputs": [
|
836 |
-
{
|
837 |
-
"output_type": "stream",
|
838 |
-
"name": "stdout",
|
839 |
-
"text": [
|
840 |
-
"{reimagined</w>|\n",
|
841 |
-
"movie</w>|\n",
|
842 |
-
"4k vivid colors|\n",
|
843 |
-
"movie still|\n",
|
844 |
-
"Movie still|\n",
|
845 |
-
"heroine</w>|\n",
|
846 |
-
"amazon</w>|\n",
|
847 |
-
"taun-|\n",
|
848 |
-
"alliance</w>|\n",
|
849 |
-
"reminis-|\n",
|
850 |
-
"premiere</w>|\n",
|
851 |
-
"honor-|\n",
|
852 |
-
"artemis</w>|\n",
|
853 |
-
"blue archive|\n",
|
854 |
-
"guarding</w>|\n",
|
855 |
-
"purple-|\n",
|
856 |
-
"protectors</w>|\n",
|
857 |
-
"Concept art|\n",
|
858 |
-
"concept art|\n",
|
859 |
-
"mags</w>|\n",
|
860 |
-
"cinematic still|\n",
|
861 |
-
"Cinematic still|\n",
|
862 |
-
"epic fantasy|\n",
|
863 |
-
"athena</w>|\n",
|
864 |
-
"ragnarok</w>|\n",
|
865 |
-
"bloo-|\n",
|
866 |
-
"special effects|\n",
|
867 |
-
"rained</w>|\n",
|
868 |
-
"vibrant arthouse|\n",
|
869 |
-
"clones</w>|\n",
|
870 |
-
"cinema art|\n",
|
871 |
-
"elves</w>|\n",
|
872 |
-
"movie texture|\n",
|
873 |
-
"anarch-|\n",
|
874 |
-
"oxi-|\n",
|
875 |
-
"sura-|\n",
|
876 |
-
"widow</w>|\n",
|
877 |
-
"vibrant Concept art|\n",
|
878 |
-
"goddess</w>|\n",
|
879 |
-
"Masterpiece Sci-Fi|\n",
|
880 |
-
"recruited</w>|\n",
|
881 |
-
"terra</w>|\n",
|
882 |
-
"sirens</w>|\n",
|
883 |
-
"defiance</w>|\n",
|
884 |
-
"sprite</w>|\n",
|
885 |
-
"soaked</w>|\n",
|
886 |
-
"kavan-|\n",
|
887 |
-
"holocau-|\n",
|
888 |
-
"soldiers</w>|\n",
|
889 |
-
"artstation|\n",
|
890 |
-
"valor</w>|\n",
|
891 |
-
"etty</w>|\n",
|
892 |
-
"marshals</w>|\n",
|
893 |
-
"clint</w>|\n",
|
894 |
-
"hd 8k masterpiece|\n",
|
895 |
-
"bluec-|\n",
|
896 |
-
"poppins</w>|\n",
|
897 |
-
"deeps darks|\n",
|
898 |
-
"hera</w>|\n",
|
899 |
-
"marvel 1girl|\n",
|
900 |
-
"guardian</w>|\n",
|
901 |
-
"references</w>|\n",
|
902 |
-
"woman solo|\n",
|
903 |
-
"4K 2girl|\n",
|
904 |
-
"characters</w>|\n",
|
905 |
-
"resolve</w>|\n",
|
906 |
-
"hail</w>|\n",
|
907 |
-
"sarmy</w>|\n",
|
908 |
-
"watched</w>|\n",
|
909 |
-
"drow-|\n",
|
910 |
-
"absurdres highres|\n",
|
911 |
-
"ogue</w>|\n",
|
912 |
-
"eq-|\n",
|
913 |
-
"snapped</w>|\n",
|
914 |
-
"atrix</w>|\n",
|
915 |
-
"navis</w>|\n",
|
916 |
-
"bodypaint|\n",
|
917 |
-
"striking</w>|\n",
|
918 |
-
"in that scene|\n",
|
919 |
-
"legion-|\n",
|
920 |
-
"hue-|\n",
|
921 |
-
"empowered</w>|\n",
|
922 |
-
"faction</w>|\n",
|
923 |
-
"widows</w>|\n",
|
924 |
-
"1girl vast|\n",
|
925 |
-
"destiny</w>|\n",
|
926 |
-
"visually</w>|\n",
|
927 |
-
"aspirations</w>|\n",
|
928 |
-
"tson</w>|\n",
|
929 |
-
"highres ultrares|\n",
|
930 |
-
"tali-|\n",
|
931 |
-
"swoon</w>|\n",
|
932 |
-
"aroo</w>|\n",
|
933 |
-
"oxi</w>|\n",
|
934 |
-
"blue filter|\n",
|
935 |
-
"blue theme|\n",
|
936 |
-
"women</w>|\n",
|
937 |
-
"orah</w>|\n",
|
938 |
-
"backlash</w>|\n",
|
939 |
-
"legendof-}\n"
|
940 |
-
]
|
941 |
-
}
|
942 |
-
]
|
943 |
},
|
944 |
{
|
945 |
"cell_type": "code",
|
@@ -992,19 +522,7 @@
|
|
992 |
{
|
993 |
"cell_type": "code",
|
994 |
"source": [
|
995 |
-
"
|
996 |
-
"!git clone https://huggingface.co/datasets/codeShare/text-to-image-prompts"
|
997 |
-
],
|
998 |
-
"metadata": {
|
999 |
-
"id": "GPAUFxZgPfrY"
|
1000 |
-
},
|
1001 |
-
"execution_count": null,
|
1002 |
-
"outputs": []
|
1003 |
-
},
|
1004 |
-
{
|
1005 |
-
"cell_type": "code",
|
1006 |
-
"source": [
|
1007 |
-
"# @title Make your own text_encodings .pt file for later use (using GPU is recommended to speed things up)\n",
|
1008 |
"\n",
|
1009 |
"import json\n",
|
1010 |
"import pandas as pd\n",
|
@@ -1013,9 +531,16 @@
|
|
1013 |
"import torch\n",
|
1014 |
"from safetensors.torch import save_file\n",
|
1015 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1016 |
"def my_mkdirs(folder):\n",
|
1017 |
-
"
|
1018 |
-
"
|
1019 |
"\n",
|
1020 |
"device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\n",
|
1021 |
"from transformers import AutoTokenizer\n",
|
@@ -1024,52 +549,53 @@
|
|
1024 |
"processor = CLIPProcessor.from_pretrained(\"openai/clip-vit-large-patch14\" , clean_up_tokenization_spaces = True)\n",
|
1025 |
"model = CLIPModel.from_pretrained(\"openai/clip-vit-large-patch14\").to(device)\n",
|
1026 |
"\n",
|
1027 |
-
"%cd
|
1028 |
-
"\n",
|
1029 |
-
"my_mkdirs('/content/text_encodings/')\n",
|
1030 |
-
"filename = ''\n",
|
1031 |
-
"\n",
|
1032 |
-
"NUM_FILES = 9\n",
|
1033 |
"\n",
|
1034 |
"\n",
|
1035 |
-
"
|
1036 |
-
"
|
1037 |
-
"with open(filename + '.json', 'r') as f:\n",
|
1038 |
-
" data = json.load(f)\n",
|
1039 |
-
"_df = pd.DataFrame({'count': data})['count']\n",
|
1040 |
-
"firstname = {\n",
|
1041 |
-
" key : value for key, value in _df.items()\n",
|
1042 |
-
"}\n",
|
1043 |
"\n",
|
1044 |
-
"NUM_FIRSTNAME = 100901\n",
|
1045 |
"\n",
|
|
|
1046 |
"for file_index in range(NUM_FILES + 1):\n",
|
1047 |
-
"
|
1048 |
-
"
|
1049 |
-
" filename = f'👱_♀️ fusion-t2i-lastnames-1 plugin-{file_index}'\n",
|
1050 |
-
" #🦜 fusion-t2i-prompt-features-1.json\n",
|
1051 |
"\n",
|
1052 |
" # Read suffix.json\n",
|
1053 |
-
"
|
1054 |
-
"
|
1055 |
-
"
|
1056 |
-
"
|
1057 |
-
"
|
1058 |
-
"
|
1059 |
-
"
|
1060 |
-
"
|
1061 |
-
"
|
1062 |
"\n",
|
1063 |
" # Calculate text_encoding for .json file contents and results as .db file\n",
|
1064 |
"\n",
|
1065 |
-
"
|
1066 |
-
"
|
1067 |
-
"
|
1068 |
-
"
|
1069 |
-
"
|
1070 |
-
"
|
1071 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1072 |
" save_file(text_encoding_dict, f'{filename}.safetensors')\n",
|
|
|
|
|
1073 |
" #----#\n",
|
1074 |
"\n",
|
1075 |
"#from safetensors.torch import load_file\n",
|
@@ -1086,9 +612,9 @@
|
|
1086 |
{
|
1087 |
"cell_type": "code",
|
1088 |
"source": [
|
1089 |
-
"# @title Download the
|
1090 |
"%cd /content/\n",
|
1091 |
-
"!zip -r /content/
|
1092 |
],
|
1093 |
"metadata": {
|
1094 |
"id": "gX-sHZPWj4Lt"
|
@@ -1099,315 +625,50 @@
|
|
1099 |
{
|
1100 |
"cell_type": "code",
|
1101 |
"source": [
|
1102 |
-
"# @title
|
1103 |
-
"
|
1104 |
-
"
|
|
|
|
|
1105 |
"import shelve\n",
|
1106 |
-
"
|
1107 |
-
"
|
1108 |
-
"# @markdown # What do you want to to mimic?\n",
|
1109 |
-
"use = '🖼️image_encoding from image' # @param ['📝text_encoding from prompt', '🖼️image_encoding from image']\n",
|
1110 |
-
"# @markdown --------------------------\n",
|
1111 |
-
"use_token_padding = True # param {type:\"boolean\"} <---- Enabled by default\n",
|
1112 |
-
"prompt = \"photo of a banana\" # @param {\"type\":\"string\",\"placeholder\":\"Write a prompt\"}\n",
|
1113 |
-
"#-----#\n",
|
1114 |
-
"prompt_A = prompt\n",
|
1115 |
-
"if(image_path != \"\") : image_A = cv2.imread(\"/content/sd_tokens/\" + image_path)\n",
|
1116 |
-
"#-----#\n",
|
1117 |
"\n",
|
1118 |
-
"
|
1119 |
-
"
|
1120 |
-
"
|
1121 |
-
"processor = CLIPProcessor.from_pretrained(\"openai/clip-vit-large-patch14\" , clean_up_tokenization_spaces = True)\n",
|
1122 |
-
"model = CLIPModel.from_pretrained(\"openai/clip-vit-large-patch14\")\n",
|
1123 |
-
"#-----#\n",
|
1124 |
-
"if(use == '🖼️image_encoding from image'):\n",
|
1125 |
-
" # Get image features\n",
|
1126 |
-
" inputs = processor(images=image_A, return_tensors=\"pt\")\n",
|
1127 |
-
" image_features = model.get_image_features(**inputs)\n",
|
1128 |
-
" image_features = image_features / image_features.norm(p=2, dim=-1, keepdim=True)\n",
|
1129 |
-
" name_A = \"the image\"\n",
|
1130 |
-
"#-----#\n",
|
1131 |
-
"if(use == '📝text_encoding from prompt'):\n",
|
1132 |
-
" # Get text features\n",
|
1133 |
-
" inputs = tokenizer(text = prompt, padding=True, return_tensors=\"pt\")\n",
|
1134 |
-
" text_features_A = model.get_text_features(**inputs)\n",
|
1135 |
-
" name_A = prompt\n",
|
1136 |
-
"#-----#\n",
|
1137 |
-
"# @markdown # The output...\n",
|
1138 |
-
"must_start_with = \"\" # @param {\"type\":\"string\",\"placeholder\":\"write a text\"}\n",
|
1139 |
-
"must_contain = \"\" # @param {\"type\":\"string\",\"placeholder\":\"write a text\"}\n",
|
1140 |
-
"must_end_with = \"\" # @param {\"type\":\"string\",\"placeholder\":\"write a text\"}\n",
|
1141 |
-
"# @markdown -----\n",
|
1142 |
-
"# @markdown # Use a range of tokens from the vocab.json (slow method)\n",
|
1143 |
-
"start_search_at_index = 0 # @param {type:\"slider\", min:0, max: 49407, step:100}\n",
|
1144 |
-
"# @markdown The lower the start_index, the more similiar the sampled tokens will be to the target token assigned in the '⚡ Get similiar tokens' cell\". If the cell was not run, then it will use tokens ordered by similarity to the \"girl\\</w>\" token\n",
|
1145 |
-
"start_search_at_ID = start_search_at_index\n",
|
1146 |
-
"search_range = 1000 # @param {type:\"slider\", min:100, max:49407, step:100}\n",
|
1147 |
"\n",
|
1148 |
-
"samples_per_iter = 10 # @param {type:\"slider\", min:10, max: 100, step:10}\n",
|
1149 |
"\n",
|
1150 |
-
"
|
1151 |
-
"
|
1152 |
-
"
|
1153 |
-
"
|
1154 |
-
"
|
1155 |
-
"
|
1156 |
-
"
|
1157 |
-
"
|
1158 |
-
"
|
1159 |
-
"
|
1160 |
-
"#-----#\n",
|
1161 |
-
"START = start_search_at_ID\n",
|
1162 |
-
"RANGE = min(search_range , max(1,NUM_TOKENS - start_search_at_ID))\n",
|
1163 |
-
"#-----#\n",
|
1164 |
-
"import math, random\n",
|
1165 |
-
"NUM_PERMUTATIONS = 6\n",
|
1166 |
-
"ITERS = iterations\n",
|
1167 |
-
"#-----#\n",
|
1168 |
-
"#LOOP START\n",
|
1169 |
-
"#-----#\n",
|
1170 |
-
"# Check if original solution is best\n",
|
1171 |
-
"best_sim = 0\n",
|
1172 |
-
"name = must_start_with + must_contain + must_end_with\n",
|
1173 |
-
"ids = processor.tokenizer(text=name, padding=use_token_padding, return_tensors=\"pt\")\n",
|
1174 |
-
"text_features = model.get_text_features(**ids)\n",
|
1175 |
-
"text_features = text_features / text_features.norm(p=2, dim=-1, keepdim=True)\n",
|
1176 |
-
"#------#\n",
|
1177 |
-
"sim = 0\n",
|
1178 |
-
"if(use == '🖼️image_encoding from image'):\n",
|
1179 |
-
" logit_scale = model.logit_scale.exp()\n",
|
1180 |
-
" torch.matmul(text_features, image_features.t()) * logit_scale\n",
|
1181 |
-
" sim = torch.nn.functional.cosine_similarity(text_features, image_features) * logit_scale\n",
|
1182 |
-
"#-----#\n",
|
1183 |
-
"if(use == '📝text_encoding from prompt'):\n",
|
1184 |
-
" sim = torch.nn.functional.cosine_similarity(text_features, text_features_A)\n",
|
1185 |
-
"#-----#\n",
|
1186 |
-
"best_sim = sim\n",
|
1187 |
-
"best_name = name\n",
|
1188 |
-
"name_B = must_contain\n",
|
1189 |
"#------#\n",
|
1190 |
-
"
|
1191 |
-
"
|
1192 |
-
"
|
1193 |
-
"
|
1194 |
-
"
|
1195 |
-
"
|
1196 |
-
"
|
|
|
|
|
|
|
1197 |
"\n",
|
1198 |
-
"
|
|
|
1199 |
"\n",
|
1200 |
-
" for index in range(samples_per_iter):\n",
|
1201 |
-
" _start = START\n",
|
1202 |
-
" id_C = random.randint(_start , _start + RANGE)\n",
|
1203 |
-
" name_C = db_vocab[f'{id_C}']\n",
|
1204 |
-
" is_Prefix = 0\n",
|
1205 |
-
" #Skip if non-AZ characters are found\n",
|
1206 |
-
" #???\n",
|
1207 |
-
" #-----#\n",
|
1208 |
-
" # Decide if we should process prefix/suffix tokens\n",
|
1209 |
-
" if name_C.find('</w>')<=-1:\n",
|
1210 |
-
" is_Prefix = 1\n",
|
1211 |
-
" if restrictions != \"Prefix only\":\n",
|
1212 |
-
" continue\n",
|
1213 |
-
" else:\n",
|
1214 |
-
" if restrictions == \"Prefix only\":\n",
|
1215 |
-
" continue\n",
|
1216 |
-
" #-----#\n",
|
1217 |
-
" # Decide if char-size is within range\n",
|
1218 |
-
" if len(name_C) < min_char_size:\n",
|
1219 |
-
" continue\n",
|
1220 |
-
" if len(name_C) > min_char_size + char_range:\n",
|
1221 |
-
" continue\n",
|
1222 |
-
" #-----#\n",
|
1223 |
-
" name_CB = must_start_with + name_C + name_B + must_end_with\n",
|
1224 |
-
" if is_Prefix>0:\n",
|
1225 |
-
" name_CB = must_start_with + ' ' + name_C + '-' + name_B + ' ' + must_end_with\n",
|
1226 |
-
" #-----#\n",
|
1227 |
-
" if(use == '🖼️image_encoding from image'):\n",
|
1228 |
-
" ids_CB = processor.tokenizer(text=name_CB, padding=use_token_padding, return_tensors=\"pt\")\n",
|
1229 |
-
" text_features = model.get_text_features(**ids_CB)\n",
|
1230 |
-
" text_features = text_features / text_features.norm(p=2, dim=-1, keepdim=True)\n",
|
1231 |
-
" logit_scale = model.logit_scale.exp()\n",
|
1232 |
-
" torch.matmul(text_features, image_features.t()) * logit_scale\n",
|
1233 |
-
" sim_CB = torch.nn.functional.cosine_similarity(text_features, image_features) * logit_scale\n",
|
1234 |
-
" #-----#\n",
|
1235 |
-
" if(use == '📝text_encoding from prompt'):\n",
|
1236 |
-
" ids_CB = processor.tokenizer(text=name_CB, padding=use_token_padding, return_tensors=\"pt\")\n",
|
1237 |
-
" text_features = model.get_text_features(**ids_CB)\n",
|
1238 |
-
" text_features = text_features / text_features.norm(p=2, dim=-1, keepdim=True)\n",
|
1239 |
-
" sim_CB = torch.nn.functional.cosine_similarity(text_features, text_features_A)\n",
|
1240 |
-
" #-----#\n",
|
1241 |
-
" #-----#\n",
|
1242 |
-
" if restrictions == \"Prefix only\":\n",
|
1243 |
-
" result = sim_CB\n",
|
1244 |
-
" result = result.item()\n",
|
1245 |
-
" dots[index] = result\n",
|
1246 |
-
" continue\n",
|
1247 |
-
" #-----#\n",
|
1248 |
-
" if(use == '🖼️image_encoding from image'):\n",
|
1249 |
-
" name_BC = must_start_with + name_B + name_C + must_end_with\n",
|
1250 |
-
" ids_BC = processor.tokenizer(text=name_BC, padding=use_token_padding, return_tensors=\"pt\")\n",
|
1251 |
-
" text_features = model.get_text_features(**ids_BC)\n",
|
1252 |
-
" text_features = text_features / text_features.norm(p=2, dim=-1, keepdim=True)\n",
|
1253 |
-
" logit_scale = model.logit_scale.exp()\n",
|
1254 |
-
" torch.matmul(text_features, image_features.t()) * logit_scale\n",
|
1255 |
-
" sim_BC = torch.nn.functional.cosine_similarity(text_features, image_features) * logit_scale\n",
|
1256 |
-
" #-----#\n",
|
1257 |
-
" if(use == '📝text_encoding from prompt'):\n",
|
1258 |
-
" name_BC = must_start_with + name_B + name_C + must_end_with\n",
|
1259 |
-
" ids_BC = processor.tokenizer(text=name_BC, padding=use_token_padding, return_tensors=\"pt\")\n",
|
1260 |
-
" text_features = model.get_text_features(**ids_BC)\n",
|
1261 |
-
" text_features = text_features / text_features.norm(p=2, dim=-1, keepdim=True)\n",
|
1262 |
-
" sim_BC = torch.nn.functional.cosine_similarity(text_features, text_features_A)\n",
|
1263 |
-
" #-----#\n",
|
1264 |
-
" result = sim_CB\n",
|
1265 |
-
" if(sim_BC > sim_CB):\n",
|
1266 |
-
" is_trail[index] = 1\n",
|
1267 |
-
" result = sim_BC\n",
|
1268 |
-
" #-----#\n",
|
1269 |
-
" #result = absolute_value(result.item())\n",
|
1270 |
-
" result = result.item()\n",
|
1271 |
-
" dots[index] = result\n",
|
1272 |
-
" #----#\n",
|
1273 |
-
" sorted, indices = torch.sort(dots,dim=0 , descending=True)\n",
|
1274 |
-
" # @markdown ----------\n",
|
1275 |
-
" # @markdown # Print options\n",
|
1276 |
-
" list_size = 100 # param {type:'number'}\n",
|
1277 |
-
" print_ID = False # @param {type:\"boolean\"}\n",
|
1278 |
-
" print_Similarity = True # @param {type:\"boolean\"}\n",
|
1279 |
-
" print_Name = True # @param {type:\"boolean\"}\n",
|
1280 |
-
" print_Divider = True # @param {type:\"boolean\"}\n",
|
1281 |
-
" print_Suggestions = False # @param {type:\"boolean\"}\n",
|
1282 |
-
" #----#\n",
|
1283 |
-
" if (print_Divider):\n",
|
1284 |
-
" print('//---//')\n",
|
1285 |
-
" #----#\n",
|
1286 |
-
" print('')\n",
|
1287 |
-
"\n",
|
1288 |
-
" used_reference = f'the text_encoding for {prompt_A}'\n",
|
1289 |
-
" if(use == '🖼️image_encoding from image'):\n",
|
1290 |
-
" used_reference = 'the image input'\n",
|
1291 |
-
" print(f'These token pairings within the range ID = {_start} to ID = {_start + RANGE} most closely match {used_reference}: ')\n",
|
1292 |
-
" print('')\n",
|
1293 |
-
" #----#\n",
|
1294 |
-
" aheads = \"{\"\n",
|
1295 |
-
" trails = \"{\"\n",
|
1296 |
-
" tmp = \"\"\n",
|
1297 |
-
" #----#\n",
|
1298 |
-
" max_sim_ahead = 0\n",
|
1299 |
-
" max_sim_trail = 0\n",
|
1300 |
-
" sim = 0\n",
|
1301 |
-
" max_name_ahead = ''\n",
|
1302 |
-
" max_name_trail = ''\n",
|
1303 |
-
" #----#\n",
|
1304 |
-
" for index in range(min(list_size,RANGE)):\n",
|
1305 |
-
" id = _start + indices[index].item()\n",
|
1306 |
-
" name = db_vocab[f'{id}']\n",
|
1307 |
-
" #-----#\n",
|
1308 |
-
" if (name.find('</w>')<=-1):\n",
|
1309 |
-
" name = name + '-'\n",
|
1310 |
-
" if(is_trail[index]>0):\n",
|
1311 |
-
" trails = trails + name + \"|\"\n",
|
1312 |
-
" else:\n",
|
1313 |
-
" aheads = aheads + name + \"|\"\n",
|
1314 |
-
" #----#\n",
|
1315 |
-
" sim = sorted[index].item()\n",
|
1316 |
-
" #----#\n",
|
1317 |
-
" if(is_trail[index]>0):\n",
|
1318 |
-
" if sim>max_sim_trail:\n",
|
1319 |
-
" max_sim_trail = sim\n",
|
1320 |
-
" max_name_trail = name\n",
|
1321 |
-
" max_name_trail = max_name_trail.strip()\n",
|
1322 |
-
"\n",
|
1323 |
-
" else:\n",
|
1324 |
-
" if sim>max_sim_ahead:\n",
|
1325 |
-
" max_sim_ahead = sim\n",
|
1326 |
-
" max_name_ahead = name\n",
|
1327 |
-
" #------#\n",
|
1328 |
-
" trails = (trails + \"&&&&\").replace(\"|&&&&\", \"}\").replace(\"</w>\", \" \").replace(\"{&&&&\", \"\")\n",
|
1329 |
-
" aheads = (aheads + \"&&&&\").replace(\"|&&&&\", \"}\").replace(\"</w>\", \" \").replace(\"{&&&&\", \"\")\n",
|
1330 |
-
" #-----#\n",
|
1331 |
-
"\n",
|
1332 |
-
" if(print_Suggestions):\n",
|
1333 |
-
" print(f\"place these items ahead of prompt : {aheads}\")\n",
|
1334 |
-
" print(\"\")\n",
|
1335 |
-
" print(f\"place these items behind the prompt : {trails}\")\n",
|
1336 |
-
" print(\"\")\n",
|
1337 |
-
"\n",
|
1338 |
-
" tmp = must_start_with + ' ' + max_name_ahead + name_B + ' ' + must_end_with\n",
|
1339 |
-
" tmp = tmp.strip().replace('</w>', ' ')\n",
|
1340 |
-
" print(f\"max_similarity_ahead = {round(max_sim_ahead,2)} % when using '{tmp}' \")\n",
|
1341 |
-
" print(\"\")\n",
|
1342 |
-
" tmp = must_start_with + ' ' + name_B + max_name_trail + ' ' + must_end_with\n",
|
1343 |
-
" tmp = tmp.strip().replace('</w>', ' ')\n",
|
1344 |
-
" print(f\"max_similarity_trail = {round(max_sim_trail,2)} % when using '{tmp}' \")\n",
|
1345 |
-
" #-----#\n",
|
1346 |
-
" #STEP 2\n",
|
1347 |
-
" import random\n",
|
1348 |
-
" #-----#\n",
|
1349 |
-
" for index in range(NUM_PERMUTATIONS):\n",
|
1350 |
-
" name_inner = ''\n",
|
1351 |
-
" if index == 0 : name_inner = name_B\n",
|
1352 |
-
" if index == 1: name_inner = max_name_ahead\n",
|
1353 |
-
" if index == 2: name_inner = max_name_trail\n",
|
1354 |
-
" if index == 3: name_inner = name_B + max_name_trail\n",
|
1355 |
-
" if index == 4: name_inner = max_name_ahead + name_B\n",
|
1356 |
-
" if index == 5: name_inner = max_name_ahead + name_B + max_name_trail\n",
|
1357 |
-
" if name_inner == '': name_inner = max_name_ahead + name_B + max_name_trail\n",
|
1358 |
-
"\n",
|
1359 |
-
" name = must_start_with + name_inner + must_end_with\n",
|
1360 |
-
" #----#\n",
|
1361 |
-
" ids = processor.tokenizer(text=name, padding=use_token_padding, return_tensors=\"pt\")\n",
|
1362 |
-
" #----#\n",
|
1363 |
-
" sim = 0\n",
|
1364 |
-
" if(use == '🖼️image_encoding from image'):\n",
|
1365 |
-
" text_features = model.get_text_features(**ids)\n",
|
1366 |
-
" text_features = text_features / text_features.norm(p=2, dim=-1, keepdim=True)\n",
|
1367 |
-
" logit_scale = model.logit_scale.exp()\n",
|
1368 |
-
" torch.matmul(text_features, image_features.t()) * logit_scale\n",
|
1369 |
-
" sim = torch.nn.functional.cosine_similarity(text_features, image_features) * logit_scale\n",
|
1370 |
-
" #-----#\n",
|
1371 |
-
" if(use == '📝text_encoding from prompt'):\n",
|
1372 |
-
" text_features = model.get_text_features(**ids)\n",
|
1373 |
-
" text_features = text_features / text_features.norm(p=2, dim=-1, keepdim=True)\n",
|
1374 |
-
" sim = torch.nn.functional.cosine_similarity(text_features, text_features_A)\n",
|
1375 |
-
" #-----#\n",
|
1376 |
-
" results_name[iter*NUM_PERMUTATIONS + index] = name\n",
|
1377 |
-
" results_sim[iter*NUM_PERMUTATIONS + index] = sim\n",
|
1378 |
-
" results_name_B[iter*NUM_PERMUTATIONS + index] = name_inner.replace('</w>',' ')\n",
|
1379 |
-
" #------#\n",
|
1380 |
-
" #name_B = results_name_B[iter*NUM_PERMUTATIONS + random.randint(0,3)]\n",
|
1381 |
-
" tmp = iter*NUM_PERMUTATIONS\n",
|
1382 |
-
" _name_B=''\n",
|
1383 |
-
" if results_sim[tmp+1]>results_sim[tmp+2]: _name_B = results_name_B[tmp + 3]\n",
|
1384 |
-
" if results_sim[tmp+2]>results_sim[tmp+1]: _name_B = results_name_B[tmp + 4]\n",
|
1385 |
-
"\n",
|
1386 |
-
" if _name_B != name_B:\n",
|
1387 |
-
" name_B=_name_B\n",
|
1388 |
-
" else:\n",
|
1389 |
-
" name_B = results_name_B[tmp + 5]\n",
|
1390 |
-
"\n",
|
1391 |
-
"#--------#\n",
|
1392 |
-
"print('')\n",
|
1393 |
-
"if(use == '🖼️image_encoding from image' and colab_image_path != \"\"):\n",
|
1394 |
-
" from google.colab.patches import cv2_imshow\n",
|
1395 |
-
" cv2_imshow(image_A)\n",
|
1396 |
-
"#-----#\n",
|
1397 |
-
"print('')\n",
|
1398 |
-
"sorted, indices = torch.sort(results_sim,dim=0 , descending=True)\n",
|
1399 |
"\n",
|
1400 |
-
"
|
1401 |
-
" name_inner = results_name[indices[index].item()]\n",
|
1402 |
-
" print(must_start_with + name_inner + must_end_with)\n",
|
1403 |
-
" print(f'similiarity = {round(sorted[index].item(),2)} %')\n",
|
1404 |
-
" print('------')\n",
|
1405 |
-
"#------#\n",
|
1406 |
-
"db_vocab.close() #close the file"
|
1407 |
],
|
1408 |
"metadata": {
|
1409 |
-
"
|
1410 |
-
"id": "fi0jRruI0-tu"
|
1411 |
},
|
1412 |
"execution_count": null,
|
1413 |
"outputs": []
|
@@ -2043,14 +1304,19 @@
|
|
2043 |
" for key in names:\n",
|
2044 |
" index = index + 1\n",
|
2045 |
" #-----#\n",
|
|
|
|
|
2046 |
"\n",
|
2047 |
-
"
|
2048 |
-
"
|
2049 |
-
"\n",
|
|
|
|
|
|
|
2050 |
" txt_filename = f'👱_♀️female_fullnames-{file_index}'\n",
|
2051 |
" %cd /content/female_full_names/\n",
|
2052 |
" with open(txt_filename + '.txt', 'w') as f:\n",
|
2053 |
-
" f.write(str(
|
2054 |
"\n",
|
2055 |
" #files.download(f'fullnames-{file_index}.txt')\n",
|
2056 |
"\n",
|
@@ -2074,7 +1340,346 @@
|
|
2074 |
"!zip -r /content/female_full_names.zip /content/female_full_names/"
|
2075 |
],
|
2076 |
"metadata": {
|
2077 |
-
"id": "IBenvYVrofil"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2078 |
},
|
2079 |
"execution_count": null,
|
2080 |
"outputs": []
|
|
|
123 |
],
|
124 |
"metadata": {
|
125 |
"id": "rUXQ73IbonHY",
|
126 |
+
"outputId": "5ce85c43-136a-49b5-f316-a74e70085e88",
|
127 |
"colab": {
|
128 |
"base_uri": "https://localhost:8080/"
|
129 |
}
|
|
|
136 |
"text": [
|
137 |
"/content\n",
|
138 |
"Cloning into 'text-to-image-prompts'...\n",
|
139 |
+
"remote: Enumerating objects: 521, done.\u001b[K\n",
|
140 |
+
"remote: Counting objects: 100% (518/518), done.\u001b[K\n",
|
141 |
+
"remote: Compressing objects: 100% (492/492), done.\u001b[K\n",
|
142 |
+
"remote: Total 521 (delta 91), reused 0 (delta 0), pack-reused 3 (from 1)\u001b[K\n",
|
143 |
+
"Receiving objects: 100% (521/521), 2.51 MiB | 6.14 MiB/s, done.\n",
|
144 |
+
"Resolving deltas: 100% (91/91), done.\n",
|
145 |
+
"Filtering content: 100% (95/95), 305.98 MiB | 37.71 MiB/s, done.\n"
|
146 |
]
|
147 |
}
|
148 |
]
|
|
|
223 |
"NUM_VOCAB_ITEMS = nA\n"
|
224 |
],
|
225 |
"metadata": {
|
226 |
+
"id": "ZMG4CThUAmwW"
|
|
|
|
|
|
|
|
|
227 |
},
|
228 |
"execution_count": null,
|
229 |
+
"outputs": []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
},
|
231 |
{
|
232 |
"cell_type": "code",
|
|
|
307 |
"#-------#"
|
308 |
],
|
309 |
"metadata": {
|
310 |
+
"id": "_vnVbxcFf7WV"
|
|
|
|
|
|
|
|
|
311 |
},
|
312 |
"execution_count": null,
|
313 |
+
"outputs": []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
},
|
315 |
{
|
316 |
"cell_type": "markdown",
|
|
|
466 |
"#-------#"
|
467 |
],
|
468 |
"metadata": {
|
469 |
+
"id": "JkzncP8SgKtS"
|
|
|
|
|
|
|
|
|
470 |
},
|
471 |
"execution_count": null,
|
472 |
+
"outputs": []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
473 |
},
|
474 |
{
|
475 |
"cell_type": "code",
|
|
|
522 |
{
|
523 |
"cell_type": "code",
|
524 |
"source": [
|
525 |
+
"# @title Make your own text_encodings .safetensor file for later use (using GPU is recommended to speed things up)\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
526 |
"\n",
|
527 |
"import json\n",
|
528 |
"import pandas as pd\n",
|
|
|
531 |
"import torch\n",
|
532 |
"from safetensors.torch import save_file\n",
|
533 |
"\n",
|
534 |
+
"using_Kaggle = False #Use https://www.kaggle.com/ if Google Colab GPU is busy\n",
|
535 |
+
"\n",
|
536 |
+
"home_directory = '/content/'\n",
|
537 |
+
"if using_Kaggle : home_directory = '/kaggle/working/'\n",
|
538 |
+
"output_folder = home_directory + 'text_encodings/'\n",
|
539 |
+
"target = home_directory + 'text-to-image-prompts/names/celebs/mixed/text'\n",
|
540 |
+
"\n",
|
541 |
"def my_mkdirs(folder):\n",
|
542 |
+
" if os.path.exists(folder)==False:\n",
|
543 |
+
" os.makedirs(folder)\n",
|
544 |
"\n",
|
545 |
"device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\n",
|
546 |
"from transformers import AutoTokenizer\n",
|
|
|
549 |
"processor = CLIPProcessor.from_pretrained(\"openai/clip-vit-large-patch14\" , clean_up_tokenization_spaces = True)\n",
|
550 |
"model = CLIPModel.from_pretrained(\"openai/clip-vit-large-patch14\").to(device)\n",
|
551 |
"\n",
|
552 |
+
"%cd {home_directory}\n",
|
|
|
|
|
|
|
|
|
|
|
553 |
"\n",
|
554 |
"\n",
|
555 |
+
"my_mkdirs(home_directory +'text_encodings/')\n",
|
556 |
+
"filename = ''\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
557 |
"\n",
|
|
|
558 |
"\n",
|
559 |
+
"NUM_FILES = 1\n",
|
560 |
"for file_index in range(NUM_FILES + 1):\n",
|
561 |
+
" if (file_index < 1): continue\n",
|
562 |
+
" filename = f'🆔👨 fusion-t2i-v2-celeb-{file_index}'\n",
|
|
|
|
|
563 |
"\n",
|
564 |
" # Read suffix.json\n",
|
565 |
+
" %cd {target}\n",
|
566 |
+
" with open(filename + '.json', 'r') as f:\n",
|
567 |
+
" data = json.load(f)\n",
|
568 |
+
" _df = pd.DataFrame({'count': data})['count']\n",
|
569 |
+
" prompts = {\n",
|
570 |
+
" key : value.replace(\"</w>\",\" \") for key, value in _df.items()\n",
|
571 |
+
" }\n",
|
572 |
+
" NUM_ITEMS = int(prompts[\"0\"])\n",
|
573 |
+
" #------#\n",
|
574 |
"\n",
|
575 |
" # Calculate text_encoding for .json file contents and results as .db file\n",
|
576 |
"\n",
|
577 |
+
" %cd {output_folder}\n",
|
578 |
+
" text_encoding_dict = {}\n",
|
579 |
+
" offset = 0;\n",
|
580 |
+
" index = 0;\n",
|
581 |
+
" subby = 1;\n",
|
582 |
+
" for _index in range(NUM_ITEMS):\n",
|
583 |
+
" index = _index - offset\n",
|
584 |
+
" inputs = tokenizer(text = '' + prompts[f'{index}'], padding=True, return_tensors=\"pt\").to(device)\n",
|
585 |
+
" text_features = model.get_text_features(**inputs).to(device)\n",
|
586 |
+
" text_features = text_features/text_features.norm(p=2, dim=-1, keepdim=True)\n",
|
587 |
+
" text_encoding_dict[f'{index}'] = text_features.to(torch.device('cpu'))\n",
|
588 |
+
" if (index % 100 == 0) :\n",
|
589 |
+
" print(index)\n",
|
590 |
+
" if (index % 1000 == 0) :\n",
|
591 |
+
" save_file(text_encoding_dict, f'{filename}-{subby}.safetensors')\n",
|
592 |
+
" offset = offset + index\n",
|
593 |
+
" subby = subby + 1\n",
|
594 |
+
" text_encoding_dict = {}\n",
|
595 |
+
" continue\n",
|
596 |
" save_file(text_encoding_dict, f'{filename}.safetensors')\n",
|
597 |
+
" #-----#\n",
|
598 |
+
"\n",
|
599 |
" #----#\n",
|
600 |
"\n",
|
601 |
"#from safetensors.torch import load_file\n",
|
|
|
612 |
{
|
613 |
"cell_type": "code",
|
614 |
"source": [
|
615 |
+
"# @title Download the text_encodings as .zip\n",
|
616 |
"%cd /content/\n",
|
617 |
+
"!zip -r /content/text_encodings.zip /content/text_encodings/"
|
618 |
],
|
619 |
"metadata": {
|
620 |
"id": "gX-sHZPWj4Lt"
|
|
|
625 |
{
|
626 |
"cell_type": "code",
|
627 |
"source": [
|
628 |
+
"# @title Merge text_encodings\n",
|
629 |
+
"\n",
|
630 |
+
"import json\n",
|
631 |
+
"import pandas as pd\n",
|
632 |
+
"import os\n",
|
633 |
"import shelve\n",
|
634 |
+
"import torch\n",
|
635 |
+
"from safetensors.torch import save_file , load_file\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
636 |
"\n",
|
637 |
+
"def my_mkdirs(folder):\n",
|
638 |
+
" if os.path.exists(folder)==False:\n",
|
639 |
+
" os.makedirs(folder)\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
640 |
"\n",
|
|
|
641 |
"\n",
|
642 |
+
"using_Kaggle = False #Use https://www.kaggle.com/ if Google Colab GPU is busy\n",
|
643 |
+
"\n",
|
644 |
+
"home_directory = '/content/'\n",
|
645 |
+
"if using_Kaggle : home_directory = '/kaggle/working/'\n",
|
646 |
+
"output_folder = home_directory +'merged_text_encodings/'\n",
|
647 |
+
"my_mkdirs(f'{output_folder}')\n",
|
648 |
+
"\n",
|
649 |
+
"target = home_directory + 'text_encodings'\n",
|
650 |
+
"_filename = f'🆔👨 fusion-t2i-v2-celeb-1'\n",
|
651 |
+
"result = {}\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
652 |
"#------#\n",
|
653 |
+
"%cd {target}\n",
|
654 |
+
"for _index in range(5):\n",
|
655 |
+
" if _index <1:continue\n",
|
656 |
+
" filename = _filename + f'-{_index}'\n",
|
657 |
+
" prompts = load_file(filename + '.safetensors')\n",
|
658 |
+
" for key in prompts:\n",
|
659 |
+
" index = _index*1000 + int(key)\n",
|
660 |
+
" result[f'{index}'] = prompts[key]\n",
|
661 |
+
" #------#\n",
|
662 |
+
"#--------3\n",
|
663 |
"\n",
|
664 |
+
"%cd {output_folder}\n",
|
665 |
+
"save_file(result, f'{_filename}.safetensors')\n",
|
666 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
667 |
"\n",
|
668 |
+
"\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
669 |
],
|
670 |
"metadata": {
|
671 |
+
"id": "DNb_iJtLiuOL"
|
|
|
672 |
},
|
673 |
"execution_count": null,
|
674 |
"outputs": []
|
|
|
1304 |
" for key in names:\n",
|
1305 |
" index = index + 1\n",
|
1306 |
" #-----#\n",
|
1307 |
+
" RANGE = min(index,1000)\n",
|
1308 |
+
" output = {}\n",
|
1309 |
"\n",
|
1310 |
+
" for index in range(RANGE):\n",
|
1311 |
+
" if index >1000: break\n",
|
1312 |
+
" output[f'{index}'] = names[f'{index}']\n",
|
1313 |
+
" #-----#\n",
|
1314 |
+
" output[f'{1}'] = f'👱_♀️female_fullnames-{file_index}'\n",
|
1315 |
+
" output[f'{0}'] = f'{RANGE}'\n",
|
1316 |
" txt_filename = f'👱_♀️female_fullnames-{file_index}'\n",
|
1317 |
" %cd /content/female_full_names/\n",
|
1318 |
" with open(txt_filename + '.txt', 'w') as f:\n",
|
1319 |
+
" f.write(str(output))\n",
|
1320 |
"\n",
|
1321 |
" #files.download(f'fullnames-{file_index}.txt')\n",
|
1322 |
"\n",
|
|
|
1340 |
"!zip -r /content/female_full_names.zip /content/female_full_names/"
|
1341 |
],
|
1342 |
"metadata": {
|
1343 |
+
"id": "IBenvYVrofil",
|
1344 |
+
"outputId": "9af94446-aa17-4784-93c1-a88ba53717af",
|
1345 |
+
"colab": {
|
1346 |
+
"base_uri": "https://localhost:8080/"
|
1347 |
+
}
|
1348 |
+
},
|
1349 |
+
"execution_count": 5,
|
1350 |
+
"outputs": [
|
1351 |
+
{
|
1352 |
+
"output_type": "stream",
|
1353 |
+
"name": "stdout",
|
1354 |
+
"text": [
|
1355 |
+
"/content\n",
|
1356 |
+
" adding: content/female_full_names/ (stored 0%)\n",
|
1357 |
+
" adding: content/female_full_names/👱_♀️female_fullnames-3.txt (deflated 66%)\n",
|
1358 |
+
" adding: content/female_full_names/👱_♀️female_fullnames-8.txt (deflated 66%)\n",
|
1359 |
+
" adding: content/female_full_names/👱_♀️female_fullnames-1.txt (deflated 67%)\n",
|
1360 |
+
" adding: content/female_full_names/👱_♀️female_fullnames-9.txt (deflated 67%)\n",
|
1361 |
+
" adding: content/female_full_names/👱_♀️female_fullnames-2.txt (deflated 67%)\n",
|
1362 |
+
" adding: content/female_full_names/👱_♀️female_fullnames-6.txt (deflated 67%)\n",
|
1363 |
+
" adding: content/female_full_names/👱_♀️female_fullnames-5.txt (deflated 67%)\n",
|
1364 |
+
" adding: content/female_full_names/👱_♀️female_fullnames-4.txt (deflated 66%)\n",
|
1365 |
+
" adding: content/female_full_names/👱_♀️female_fullnames-7.txt (deflated 65%)\n"
|
1366 |
+
]
|
1367 |
+
}
|
1368 |
+
]
|
1369 |
+
},
|
1370 |
+
{
|
1371 |
+
"cell_type": "code",
|
1372 |
+
"source": [
|
1373 |
+
"# @title ⚡+🖼️ -> 📝 Token-Sampling Image interrogator (work in progress)\n",
|
1374 |
+
"#-----#\n",
|
1375 |
+
"NUM_TOKENS = 49407\n",
|
1376 |
+
"import shelve\n",
|
1377 |
+
"db_vocab = shelve.open(VOCAB_FILENAME)\n",
|
1378 |
+
"print(f'using the tokens found in {VOCAB_FILENAME}.db as the vocab')\n",
|
1379 |
+
"# @markdown # What do you want to to mimic?\n",
|
1380 |
+
"use = '🖼️image_encoding from image' # @param ['📝text_encoding from prompt', '🖼️image_encoding from image']\n",
|
1381 |
+
"# @markdown --------------------------\n",
|
1382 |
+
"use_token_padding = True # param {type:\"boolean\"} <---- Enabled by default\n",
|
1383 |
+
"prompt = \"photo of a banana\" # @param {\"type\":\"string\",\"placeholder\":\"Write a prompt\"}\n",
|
1384 |
+
"#-----#\n",
|
1385 |
+
"prompt_A = prompt\n",
|
1386 |
+
"if(image_path != \"\") : image_A = cv2.imread(\"/content/sd_tokens/\" + image_path)\n",
|
1387 |
+
"#-----#\n",
|
1388 |
+
"\n",
|
1389 |
+
"from transformers import AutoTokenizer\n",
|
1390 |
+
"tokenizer = AutoTokenizer.from_pretrained(\"openai/clip-vit-large-patch14\", clean_up_tokenization_spaces = False)\n",
|
1391 |
+
"from transformers import CLIPProcessor, CLIPModel\n",
|
1392 |
+
"processor = CLIPProcessor.from_pretrained(\"openai/clip-vit-large-patch14\" , clean_up_tokenization_spaces = True)\n",
|
1393 |
+
"model = CLIPModel.from_pretrained(\"openai/clip-vit-large-patch14\")\n",
|
1394 |
+
"#-----#\n",
|
1395 |
+
"if(use == '🖼️image_encoding from image'):\n",
|
1396 |
+
" # Get image features\n",
|
1397 |
+
" inputs = processor(images=image_A, return_tensors=\"pt\")\n",
|
1398 |
+
" image_features = model.get_image_features(**inputs)\n",
|
1399 |
+
" image_features = image_features / image_features.norm(p=2, dim=-1, keepdim=True)\n",
|
1400 |
+
" name_A = \"the image\"\n",
|
1401 |
+
"#-----#\n",
|
1402 |
+
"if(use == '📝text_encoding from prompt'):\n",
|
1403 |
+
" # Get text features\n",
|
1404 |
+
" inputs = tokenizer(text = prompt, padding=True, return_tensors=\"pt\")\n",
|
1405 |
+
" text_features_A = model.get_text_features(**inputs)\n",
|
1406 |
+
" name_A = prompt\n",
|
1407 |
+
"#-----#\n",
|
1408 |
+
"# @markdown # The output...\n",
|
1409 |
+
"must_start_with = \"\" # @param {\"type\":\"string\",\"placeholder\":\"write a text\"}\n",
|
1410 |
+
"must_contain = \"\" # @param {\"type\":\"string\",\"placeholder\":\"write a text\"}\n",
|
1411 |
+
"must_end_with = \"\" # @param {\"type\":\"string\",\"placeholder\":\"write a text\"}\n",
|
1412 |
+
"# @markdown -----\n",
|
1413 |
+
"# @markdown # Use a range of tokens from the vocab.json (slow method)\n",
|
1414 |
+
"start_search_at_index = 0 # @param {type:\"slider\", min:0, max: 49407, step:100}\n",
|
1415 |
+
"# @markdown The lower the start_index, the more similiar the sampled tokens will be to the target token assigned in the '⚡ Get similiar tokens' cell\". If the cell was not run, then it will use tokens ordered by similarity to the \"girl\\</w>\" token\n",
|
1416 |
+
"start_search_at_ID = start_search_at_index\n",
|
1417 |
+
"search_range = 1000 # @param {type:\"slider\", min:100, max:49407, step:100}\n",
|
1418 |
+
"\n",
|
1419 |
+
"samples_per_iter = 10 # @param {type:\"slider\", min:10, max: 100, step:10}\n",
|
1420 |
+
"\n",
|
1421 |
+
"iterations = 5 # @param {type:\"slider\", min:1, max: 20, step:0}\n",
|
1422 |
+
"restrictions = 'None' # @param [\"None\", \"Suffix only\", \"Prefix only\"]\n",
|
1423 |
+
"#markdown Limit char size of included token <----- Disabled\n",
|
1424 |
+
"min_char_size = 0 #param {type:\"slider\", min:0, max: 20, step:1}\n",
|
1425 |
+
"char_range = 50 #param {type:\"slider\", min:0, max: 20, step:1}\n",
|
1426 |
+
"# markdown # ...or paste prompt items\n",
|
1427 |
+
"# markdown Format must be {item1|item2|...}. You can aquire prompt items using the Randomizer in the fusion gen: https://perchance.org/fusion-ai-image-generator\n",
|
1428 |
+
"_enable = False # param {\"type\":\"boolean\"}\n",
|
1429 |
+
"prompt_items = \"\" # param {\"type\":\"string\",\"placeholder\":\"{item1|item2|...}\"}\n",
|
1430 |
+
"#-----#\n",
|
1431 |
+
"#-----#\n",
|
1432 |
+
"START = start_search_at_ID\n",
|
1433 |
+
"RANGE = min(search_range , max(1,NUM_TOKENS - start_search_at_ID))\n",
|
1434 |
+
"#-----#\n",
|
1435 |
+
"import math, random\n",
|
1436 |
+
"NUM_PERMUTATIONS = 6\n",
|
1437 |
+
"ITERS = iterations\n",
|
1438 |
+
"#-----#\n",
|
1439 |
+
"#LOOP START\n",
|
1440 |
+
"#-----#\n",
|
1441 |
+
"# Check if original solution is best\n",
|
1442 |
+
"best_sim = 0\n",
|
1443 |
+
"name = must_start_with + must_contain + must_end_with\n",
|
1444 |
+
"ids = processor.tokenizer(text=name, padding=use_token_padding, return_tensors=\"pt\")\n",
|
1445 |
+
"text_features = model.get_text_features(**ids)\n",
|
1446 |
+
"text_features = text_features / text_features.norm(p=2, dim=-1, keepdim=True)\n",
|
1447 |
+
"#------#\n",
|
1448 |
+
"sim = 0\n",
|
1449 |
+
"if(use == '🖼️image_encoding from image'):\n",
|
1450 |
+
" logit_scale = model.logit_scale.exp()\n",
|
1451 |
+
" torch.matmul(text_features, image_features.t()) * logit_scale\n",
|
1452 |
+
" sim = torch.nn.functional.cosine_similarity(text_features, image_features) * logit_scale\n",
|
1453 |
+
"#-----#\n",
|
1454 |
+
"if(use == '📝text_encoding from prompt'):\n",
|
1455 |
+
" sim = torch.nn.functional.cosine_similarity(text_features, text_features_A)\n",
|
1456 |
+
"#-----#\n",
|
1457 |
+
"best_sim = sim\n",
|
1458 |
+
"best_name = name\n",
|
1459 |
+
"name_B = must_contain\n",
|
1460 |
+
"#------#\n",
|
1461 |
+
"results_sim = torch.zeros(ITERS*NUM_PERMUTATIONS)\n",
|
1462 |
+
"results_name_B = {}\n",
|
1463 |
+
"results_name = {}\n",
|
1464 |
+
"#-----#\n",
|
1465 |
+
"for iter in range(ITERS):\n",
|
1466 |
+
" dots = torch.zeros(min(list_size,RANGE))\n",
|
1467 |
+
" is_trail = torch.zeros(min(list_size,RANGE))\n",
|
1468 |
+
"\n",
|
1469 |
+
" #-----#\n",
|
1470 |
+
"\n",
|
1471 |
+
" for index in range(samples_per_iter):\n",
|
1472 |
+
" _start = START\n",
|
1473 |
+
" id_C = random.randint(_start , _start + RANGE)\n",
|
1474 |
+
" name_C = db_vocab[f'{id_C}']\n",
|
1475 |
+
" is_Prefix = 0\n",
|
1476 |
+
" #Skip if non-AZ characters are found\n",
|
1477 |
+
" #???\n",
|
1478 |
+
" #-----#\n",
|
1479 |
+
" # Decide if we should process prefix/suffix tokens\n",
|
1480 |
+
" if name_C.find('</w>')<=-1:\n",
|
1481 |
+
" is_Prefix = 1\n",
|
1482 |
+
" if restrictions != \"Prefix only\":\n",
|
1483 |
+
" continue\n",
|
1484 |
+
" else:\n",
|
1485 |
+
" if restrictions == \"Prefix only\":\n",
|
1486 |
+
" continue\n",
|
1487 |
+
" #-----#\n",
|
1488 |
+
" # Decide if char-size is within range\n",
|
1489 |
+
" if len(name_C) < min_char_size:\n",
|
1490 |
+
" continue\n",
|
1491 |
+
" if len(name_C) > min_char_size + char_range:\n",
|
1492 |
+
" continue\n",
|
1493 |
+
" #-----#\n",
|
1494 |
+
" name_CB = must_start_with + name_C + name_B + must_end_with\n",
|
1495 |
+
" if is_Prefix>0:\n",
|
1496 |
+
" name_CB = must_start_with + ' ' + name_C + '-' + name_B + ' ' + must_end_with\n",
|
1497 |
+
" #-----#\n",
|
1498 |
+
" if(use == '🖼️image_encoding from image'):\n",
|
1499 |
+
" ids_CB = processor.tokenizer(text=name_CB, padding=use_token_padding, return_tensors=\"pt\")\n",
|
1500 |
+
" text_features = model.get_text_features(**ids_CB)\n",
|
1501 |
+
" text_features = text_features / text_features.norm(p=2, dim=-1, keepdim=True)\n",
|
1502 |
+
" logit_scale = model.logit_scale.exp()\n",
|
1503 |
+
" torch.matmul(text_features, image_features.t()) * logit_scale\n",
|
1504 |
+
" sim_CB = torch.nn.functional.cosine_similarity(text_features, image_features) * logit_scale\n",
|
1505 |
+
" #-----#\n",
|
1506 |
+
" if(use == '📝text_encoding from prompt'):\n",
|
1507 |
+
" ids_CB = processor.tokenizer(text=name_CB, padding=use_token_padding, return_tensors=\"pt\")\n",
|
1508 |
+
" text_features = model.get_text_features(**ids_CB)\n",
|
1509 |
+
" text_features = text_features / text_features.norm(p=2, dim=-1, keepdim=True)\n",
|
1510 |
+
" sim_CB = torch.nn.functional.cosine_similarity(text_features, text_features_A)\n",
|
1511 |
+
" #-----#\n",
|
1512 |
+
" #-----#\n",
|
1513 |
+
" if restrictions == \"Prefix only\":\n",
|
1514 |
+
" result = sim_CB\n",
|
1515 |
+
" result = result.item()\n",
|
1516 |
+
" dots[index] = result\n",
|
1517 |
+
" continue\n",
|
1518 |
+
" #-----#\n",
|
1519 |
+
" if(use == '🖼️image_encoding from image'):\n",
|
1520 |
+
" name_BC = must_start_with + name_B + name_C + must_end_with\n",
|
1521 |
+
" ids_BC = processor.tokenizer(text=name_BC, padding=use_token_padding, return_tensors=\"pt\")\n",
|
1522 |
+
" text_features = model.get_text_features(**ids_BC)\n",
|
1523 |
+
" text_features = text_features / text_features.norm(p=2, dim=-1, keepdim=True)\n",
|
1524 |
+
" logit_scale = model.logit_scale.exp()\n",
|
1525 |
+
" torch.matmul(text_features, image_features.t()) * logit_scale\n",
|
1526 |
+
" sim_BC = torch.nn.functional.cosine_similarity(text_features, image_features) * logit_scale\n",
|
1527 |
+
" #-----#\n",
|
1528 |
+
" if(use == '📝text_encoding from prompt'):\n",
|
1529 |
+
" name_BC = must_start_with + name_B + name_C + must_end_with\n",
|
1530 |
+
" ids_BC = processor.tokenizer(text=name_BC, padding=use_token_padding, return_tensors=\"pt\")\n",
|
1531 |
+
" text_features = model.get_text_features(**ids_BC)\n",
|
1532 |
+
" text_features = text_features / text_features.norm(p=2, dim=-1, keepdim=True)\n",
|
1533 |
+
" sim_BC = torch.nn.functional.cosine_similarity(text_features, text_features_A)\n",
|
1534 |
+
" #-----#\n",
|
1535 |
+
" result = sim_CB\n",
|
1536 |
+
" if(sim_BC > sim_CB):\n",
|
1537 |
+
" is_trail[index] = 1\n",
|
1538 |
+
" result = sim_BC\n",
|
1539 |
+
" #-----#\n",
|
1540 |
+
" #result = absolute_value(result.item())\n",
|
1541 |
+
" result = result.item()\n",
|
1542 |
+
" dots[index] = result\n",
|
1543 |
+
" #----#\n",
|
1544 |
+
" sorted, indices = torch.sort(dots,dim=0 , descending=True)\n",
|
1545 |
+
" # @markdown ----------\n",
|
1546 |
+
" # @markdown # Print options\n",
|
1547 |
+
" list_size = 100 # param {type:'number'}\n",
|
1548 |
+
" print_ID = False # @param {type:\"boolean\"}\n",
|
1549 |
+
" print_Similarity = True # @param {type:\"boolean\"}\n",
|
1550 |
+
" print_Name = True # @param {type:\"boolean\"}\n",
|
1551 |
+
" print_Divider = True # @param {type:\"boolean\"}\n",
|
1552 |
+
" print_Suggestions = False # @param {type:\"boolean\"}\n",
|
1553 |
+
" #----#\n",
|
1554 |
+
" if (print_Divider):\n",
|
1555 |
+
" print('//---//')\n",
|
1556 |
+
" #----#\n",
|
1557 |
+
" print('')\n",
|
1558 |
+
"\n",
|
1559 |
+
" used_reference = f'the text_encoding for {prompt_A}'\n",
|
1560 |
+
" if(use == '🖼️image_encoding from image'):\n",
|
1561 |
+
" used_reference = 'the image input'\n",
|
1562 |
+
" print(f'These token pairings within the range ID = {_start} to ID = {_start + RANGE} most closely match {used_reference}: ')\n",
|
1563 |
+
" print('')\n",
|
1564 |
+
" #----#\n",
|
1565 |
+
" aheads = \"{\"\n",
|
1566 |
+
" trails = \"{\"\n",
|
1567 |
+
" tmp = \"\"\n",
|
1568 |
+
" #----#\n",
|
1569 |
+
" max_sim_ahead = 0\n",
|
1570 |
+
" max_sim_trail = 0\n",
|
1571 |
+
" sim = 0\n",
|
1572 |
+
" max_name_ahead = ''\n",
|
1573 |
+
" max_name_trail = ''\n",
|
1574 |
+
" #----#\n",
|
1575 |
+
" for index in range(min(list_size,RANGE)):\n",
|
1576 |
+
" id = _start + indices[index].item()\n",
|
1577 |
+
" name = db_vocab[f'{id}']\n",
|
1578 |
+
" #-----#\n",
|
1579 |
+
" if (name.find('</w>')<=-1):\n",
|
1580 |
+
" name = name + '-'\n",
|
1581 |
+
" if(is_trail[index]>0):\n",
|
1582 |
+
" trails = trails + name + \"|\"\n",
|
1583 |
+
" else:\n",
|
1584 |
+
" aheads = aheads + name + \"|\"\n",
|
1585 |
+
" #----#\n",
|
1586 |
+
" sim = sorted[index].item()\n",
|
1587 |
+
" #----#\n",
|
1588 |
+
" if(is_trail[index]>0):\n",
|
1589 |
+
" if sim>max_sim_trail:\n",
|
1590 |
+
" max_sim_trail = sim\n",
|
1591 |
+
" max_name_trail = name\n",
|
1592 |
+
" max_name_trail = max_name_trail.strip()\n",
|
1593 |
+
"\n",
|
1594 |
+
" else:\n",
|
1595 |
+
" if sim>max_sim_ahead:\n",
|
1596 |
+
" max_sim_ahead = sim\n",
|
1597 |
+
" max_name_ahead = name\n",
|
1598 |
+
" #------#\n",
|
1599 |
+
" trails = (trails + \"&&&&\").replace(\"|&&&&\", \"}\").replace(\"</w>\", \" \").replace(\"{&&&&\", \"\")\n",
|
1600 |
+
" aheads = (aheads + \"&&&&\").replace(\"|&&&&\", \"}\").replace(\"</w>\", \" \").replace(\"{&&&&\", \"\")\n",
|
1601 |
+
" #-----#\n",
|
1602 |
+
"\n",
|
1603 |
+
" if(print_Suggestions):\n",
|
1604 |
+
" print(f\"place these items ahead of prompt : {aheads}\")\n",
|
1605 |
+
" print(\"\")\n",
|
1606 |
+
" print(f\"place these items behind the prompt : {trails}\")\n",
|
1607 |
+
" print(\"\")\n",
|
1608 |
+
"\n",
|
1609 |
+
" tmp = must_start_with + ' ' + max_name_ahead + name_B + ' ' + must_end_with\n",
|
1610 |
+
" tmp = tmp.strip().replace('</w>', ' ')\n",
|
1611 |
+
" print(f\"max_similarity_ahead = {round(max_sim_ahead,2)} % when using '{tmp}' \")\n",
|
1612 |
+
" print(\"\")\n",
|
1613 |
+
" tmp = must_start_with + ' ' + name_B + max_name_trail + ' ' + must_end_with\n",
|
1614 |
+
" tmp = tmp.strip().replace('</w>', ' ')\n",
|
1615 |
+
" print(f\"max_similarity_trail = {round(max_sim_trail,2)} % when using '{tmp}' \")\n",
|
1616 |
+
" #-----#\n",
|
1617 |
+
" #STEP 2\n",
|
1618 |
+
" import random\n",
|
1619 |
+
" #-----#\n",
|
1620 |
+
" for index in range(NUM_PERMUTATIONS):\n",
|
1621 |
+
" name_inner = ''\n",
|
1622 |
+
" if index == 0 : name_inner = name_B\n",
|
1623 |
+
" if index == 1: name_inner = max_name_ahead\n",
|
1624 |
+
" if index == 2: name_inner = max_name_trail\n",
|
1625 |
+
" if index == 3: name_inner = name_B + max_name_trail\n",
|
1626 |
+
" if index == 4: name_inner = max_name_ahead + name_B\n",
|
1627 |
+
" if index == 5: name_inner = max_name_ahead + name_B + max_name_trail\n",
|
1628 |
+
" if name_inner == '': name_inner = max_name_ahead + name_B + max_name_trail\n",
|
1629 |
+
"\n",
|
1630 |
+
" name = must_start_with + name_inner + must_end_with\n",
|
1631 |
+
" #----#\n",
|
1632 |
+
" ids = processor.tokenizer(text=name, padding=use_token_padding, return_tensors=\"pt\")\n",
|
1633 |
+
" #----#\n",
|
1634 |
+
" sim = 0\n",
|
1635 |
+
" if(use == '🖼️image_encoding from image'):\n",
|
1636 |
+
" text_features = model.get_text_features(**ids)\n",
|
1637 |
+
" text_features = text_features / text_features.norm(p=2, dim=-1, keepdim=True)\n",
|
1638 |
+
" logit_scale = model.logit_scale.exp()\n",
|
1639 |
+
" torch.matmul(text_features, image_features.t()) * logit_scale\n",
|
1640 |
+
" sim = torch.nn.functional.cosine_similarity(text_features, image_features) * logit_scale\n",
|
1641 |
+
" #-----#\n",
|
1642 |
+
" if(use == '📝text_encoding from prompt'):\n",
|
1643 |
+
" text_features = model.get_text_features(**ids)\n",
|
1644 |
+
" text_features = text_features / text_features.norm(p=2, dim=-1, keepdim=True)\n",
|
1645 |
+
" sim = torch.nn.functional.cosine_similarity(text_features, text_features_A)\n",
|
1646 |
+
" #-----#\n",
|
1647 |
+
" results_name[iter*NUM_PERMUTATIONS + index] = name\n",
|
1648 |
+
" results_sim[iter*NUM_PERMUTATIONS + index] = sim\n",
|
1649 |
+
" results_name_B[iter*NUM_PERMUTATIONS + index] = name_inner.replace('</w>',' ')\n",
|
1650 |
+
" #------#\n",
|
1651 |
+
" #name_B = results_name_B[iter*NUM_PERMUTATIONS + random.randint(0,3)]\n",
|
1652 |
+
" tmp = iter*NUM_PERMUTATIONS\n",
|
1653 |
+
" _name_B=''\n",
|
1654 |
+
" if results_sim[tmp+1]>results_sim[tmp+2]: _name_B = results_name_B[tmp + 3]\n",
|
1655 |
+
" if results_sim[tmp+2]>results_sim[tmp+1]: _name_B = results_name_B[tmp + 4]\n",
|
1656 |
+
"\n",
|
1657 |
+
" if _name_B != name_B:\n",
|
1658 |
+
" name_B=_name_B\n",
|
1659 |
+
" else:\n",
|
1660 |
+
" name_B = results_name_B[tmp + 5]\n",
|
1661 |
+
"\n",
|
1662 |
+
"#--------#\n",
|
1663 |
+
"print('')\n",
|
1664 |
+
"if(use == '🖼️image_encoding from image' and colab_image_path != \"\"):\n",
|
1665 |
+
" from google.colab.patches import cv2_imshow\n",
|
1666 |
+
" cv2_imshow(image_A)\n",
|
1667 |
+
"#-----#\n",
|
1668 |
+
"print('')\n",
|
1669 |
+
"sorted, indices = torch.sort(results_sim,dim=0 , descending=True)\n",
|
1670 |
+
"\n",
|
1671 |
+
"for index in range(ITERS*NUM_PERMUTATIONS):\n",
|
1672 |
+
" name_inner = results_name[indices[index].item()]\n",
|
1673 |
+
" print(must_start_with + name_inner + must_end_with)\n",
|
1674 |
+
" print(f'similiarity = {round(sorted[index].item(),2)} %')\n",
|
1675 |
+
" print('------')\n",
|
1676 |
+
"#------#\n",
|
1677 |
+
"db_vocab.close() #close the file"
|
1678 |
+
],
|
1679 |
+
"metadata": {
|
1680 |
+
"collapsed": true,
|
1681 |
+
"id": "fi0jRruI0-tu",
|
1682 |
+
"cellView": "form"
|
1683 |
},
|
1684 |
"execution_count": null,
|
1685 |
"outputs": []
|