codeShare commited on
Commit
3cc19b3
·
verified ·
1 Parent(s): f099a05

Upload fusion_t2i_CLIP_interrogator.ipynb

Browse files
Google Colab Jupyter Notebooks/fusion_t2i_CLIP_interrogator.ipynb CHANGED
@@ -93,9 +93,21 @@
93
  "\n",
94
  "f_add = torch.nn.quantized.FloatFunctional()\n",
95
  "\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  "index = 0\n",
97
  "%cd {home_directory + 'fusion-t2i-generator-data/' + 'vocab'}\n",
98
- "\n",
99
  "vocab_encodings = torch.load('vocab_encodings.pt', weights_only=False)\n",
100
  "for key in vocab_encodings:\n",
101
  " index = index + 1;\n",
@@ -107,10 +119,10 @@
107
  "for key in torch.load('reference_text_and_image_encodings.pt', weights_only=False):\n",
108
  " index = index + 1;\n",
109
  "#------#\n",
110
- "NUM_REFERENCE_ITEMS = index\n"
111
  ],
112
  "metadata": {
113
- "id": "TC5lMJrS1HCC"
114
  },
115
  "execution_count": null,
116
  "outputs": []
@@ -239,7 +251,7 @@
239
  "metadata": {
240
  "id": "XNHz0hfhHRUu"
241
  },
242
- "execution_count": 113,
243
  "outputs": []
244
  },
245
  {
@@ -550,6 +562,51 @@
550
  },
551
  "execution_count": null,
552
  "outputs": []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
553
  }
554
  ]
555
  }
 
93
  "\n",
94
  "f_add = torch.nn.quantized.FloatFunctional()\n",
95
  "\n",
96
+ "\n",
97
+ "\n",
98
+ "\n"
99
+ ],
100
+ "metadata": {
101
+ "id": "TC5lMJrS1HCC"
102
+ },
103
+ "execution_count": null,
104
+ "outputs": []
105
+ },
106
+ {
107
+ "cell_type": "code",
108
+ "source": [
109
  "index = 0\n",
110
  "%cd {home_directory + 'fusion-t2i-generator-data/' + 'vocab'}\n",
 
111
  "vocab_encodings = torch.load('vocab_encodings.pt', weights_only=False)\n",
112
  "for key in vocab_encodings:\n",
113
  " index = index + 1;\n",
 
119
  "for key in torch.load('reference_text_and_image_encodings.pt', weights_only=False):\n",
120
  " index = index + 1;\n",
121
  "#------#\n",
122
+ "NUM_REFERENCE_ITEMS = index"
123
  ],
124
  "metadata": {
125
+ "id": "Z8x3Y7IsnGlT"
126
  },
127
  "execution_count": null,
128
  "outputs": []
 
251
  "metadata": {
252
  "id": "XNHz0hfhHRUu"
253
  },
254
+ "execution_count": null,
255
  "outputs": []
256
  },
257
  {
 
562
  },
563
  "execution_count": null,
564
  "outputs": []
565
+ },
566
+ {
567
+ "cell_type": "code",
568
+ "source": [
569
+ "\n",
570
+ "# @title \t⚄ New code (work in progress)\n",
571
+ "\n",
572
+ "LIST_SIZE = 1000\n",
573
+ "SCALE = 0.0043\n",
574
+ "DIM = 768\n",
575
+ "\n",
576
+ "from safetensors.torch import load_file\n",
577
+ "\n",
578
+ "def get_most_similiar_items_to(ref , url , num_items):\n",
579
+ " vocab = load_file(url)\n",
580
+ "\n",
581
+ " def similarity(item):\n",
582
+ " key = item[0]\n",
583
+ " value = item[1]\n",
584
+ " tmp = torch.sub(value[1:DIM+1] , torch.ones(DIM) , alpha = value[0].item()).to(dtype=torch.uint8)\n",
585
+ " return torch.dot(tmp,ref).item()\n",
586
+ " #--------#\n",
587
+ "\n",
588
+ " return dict(sorted(vocab.items(), key=similarity))\n",
589
+ "#----------#\n",
590
+ "\n",
591
+ "ref = torch.rand(DIM)\n",
592
+ "ref = (1/SCALE) * ref/ref.norm(p=2, dim=-1, keepdim=True)\n",
593
+ "ref = torch.round(ref).to(dtype=torch.uint8)\n",
594
+ "\n",
595
+ "url = '/content/fusion-t2i-generator-data/lyrics_vocab_q0043_41905.safetensors'\n",
596
+ "test = get_most_similiar_items_to(ref , url , LIST_SIZE)\n",
597
+ "\n",
598
+ "index = 0\n",
599
+ "for key in test:\n",
600
+ " print(key)\n",
601
+ " index = index + 1\n",
602
+ " if index>=10:break\n",
603
+ "#-----#"
604
+ ],
605
+ "metadata": {
606
+ "id": "PGyLzCmYqCPg"
607
+ },
608
+ "execution_count": null,
609
+ "outputs": []
610
  }
611
  ]
612
  }