Upload sd_token_similarity_calculator.ipynb
Browse files386 unmodified lines38738838939039139239339439539639738 unmodified lines43643743843944044144244344444544644744844996 unmodified lines54654754854955055155281 unmodified lines63463563663763863964015 unmodified lines656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689386 unmodified lines"start_search_at_index = 0 # @param {type:\"slider\", min:0, max: 49407, step:100}\n","# @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","start_search_at_ID = start_search_at_index\n","search_range = 1220 # @param {type:\"slider\", min:10, max: 2000, step:10}\n","\n","samples_per_iter = 20 # @param {type:\"slider\", min:10, max: 100, step:10}\n","\n","iterations = 20 # @param {type:\"slider\", min:1, max: 20, step:0}\n","restrictions = 'None' # @param [\"None\", \"Suffix only\", \"Prefix only\"]\n","#markdown Limit char size of included token <----- Disabled\n","min_char_size = 0 #param {type:\"slider\", min:0, max: 20, step:1}\n",38 unmodified lines"results_name = {}\n","#-----#\n","for iter in range(ITERS):\n"," dots = torch.zeros(RANGE)\n"," is_trail = torch.zeros(RANGE)\n"," import re\n"," #-----#\n"," _start = START + iter*RANGE\n","\n"," for index in range(samples_per_iter):\n"," id_C = min(_start + index*RANGE, NUM_TOKENS) + random.randint(0,RANGE)\n"," name_C = db_vocab[f'{id_C}']\n"," is_Prefix = 0\n"," #Skip if non-AZ characters are found\n",96 unmodified lines" max_name_trail = ''\n"," #----#\n"," for index in range(min(list_size,RANGE)):\n"," id = START + indices[index].item()\n"," name = db_vocab[f'{id}']\n"," #-----#\n"," if (name.find('</w>')<=-1):\n",81 unmodified lines"\n","#--------#\n","print('')\n","if(use == '🖼️image_encoding from image'):\n"," from google.colab.patches import cv2_imshow\n"," cv2_imshow(image_A)\n","#-----#\n",15 unmodified lines"execution_count": null,"outputs": []},{"cell_type": "code","source": [],"metadata": {"id": "5XN2pM5NAfS5","outputId": "df4eefe6-12e7-416e-dc2d-b6df22a14d69","colab": {"base_uri": "https://localhost:8080/","height": 321}},"execution_count": 25,"outputs": [{"output_type": "error","ename": "AttributeError","evalue": "clip","traceback": ["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)","\u001b[0;32m<ipython-input-25-2eb0ffbc049b>\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mif\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0muse\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'🖼️image_encoding from image'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mgoogle\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcolab\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpatches\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mcv2_imshow\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mcv2_imshow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimage_A\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;32m/usr/local/lib/python3.10/dist-packages/google/colab/patches/__init__.py\u001b[0m in \u001b[0;36mcv2_imshow\u001b[0;34m(a)\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mM\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m4\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0man\u001b[0m \u001b[0mNxM\u001b[0m \u001b[0mBGRA\u001b[0m \u001b[0mcolor\u001b[0m \u001b[0mimage\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 17\u001b[0m \"\"\"\n\u001b[0;32m---> 18\u001b[0;31m \u001b[0ma\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m255\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'uint8'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 19\u001b[0m \u001b[0;31m# cv2 stores colors as BGR; convert to RGB\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 20\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.10/dist-packages/PIL/Image.py\u001b[0m in \u001b[0;36m__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 527\u001b[0m \u001b[0mdeprecate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Image categories\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"is_animated\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mplural\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 528\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_category\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 529\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mAttributeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 530\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 531\u001b[0m \u001b[0;34m@\u001b[0m\u001b[0mproperty\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;31mAttributeError\u001b[0m: clip"]}]},{"cell_type": "code","source": [386 unmodified lines38738838939039139239339439539639738 unmodified lines43643743843944044144244344444544644744844996 unmodified lines54654754854955055155281 unmodified lines63463563663763863964015 unmodified lines656657658659660661386 unmodified lines"start_search_at_index = 0 # @param {type:\"slider\", min:0, max: 49407, step:100}\n","# @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","start_search_at_ID = start_search_at_index\n","search_range = 1000 # @param {type:\"slider\", min:10, max: 2000, step:10}\n","\n","samples_per_iter = 10 # @param {type:\"slider\", min:10, max: 100, step:10}\n","\n","iterations = 5 # @param {type:\"slider\", min:1, max: 20, step:0}\n","restrictions = 'None' # @param [\"None\", \"Suffix only\", \"Prefix only\"]\n","#markdown Limit char size of included token <----- Disabled\n","min_char_size = 0 #param {type:\"slider\", min:0, max: 20, step:1}\n",38 unmodified lines"results_name = {}\n","#-----#\n","for iter in range(ITERS):\n"," dots = torch.zeros(min(list_size,RANGE))\n"," is_trail = torch.zeros(min(list_size,RANGE))\n","\n"," #-----#\n","\n"," for index in range(samples_per_iter):\n"," _start = START + iter*RANGE\n"," id_C = random.randint(_start , _start + RANGE)\n"," name_C = db_vocab[f'{id_C}']\n"," is_Prefix = 0\n"," #Skip if non-AZ characters are found\n",96 unmodified lines" max_name_trail = ''\n"," #----#\n"," for index in range(min(list_size,RANGE)):\n"," id = _start + indices[index].item()\n"," name = db_vocab[f'{id}']\n"," #-----#\n"," if (name.find('</w>')<=-1):\n",81 unmodified lines"\n","#--------#\n","print('')\n","if(use == '🖼️image_encoding from image' and colab_image_path != \"\"):\n"," from google.colab.patches import cv2_imshow\n"," cv2_imshow(image_A)\n","#-----#\n",15 unmodified lines"execution_count": null,"outputs": []},{"cell_type": "code","source": [
sd_token_similarity_calculator.ipynb+10-38