Upload fusion_t2i_CLIP_interrogator.ipynb
Browse files27 unmodified lines2829303132333456 unmodified lines91929394959697989910010110210310410510610710810911011111211311411511611711811912012112231 unmodified lines15415515615715815916016116214 unmodified lines1771781791801811821831841851861871887 unmodified lines19619719819920020120298 unmodified lines30130230330430530630710 unmodified lines31831932032132232332461 unmodified lines38638738838939039139210 unmodified lines40340440540640740840954 unmodified lines46446546646746846947010 unmodified lines48148248348448548648758 unmodified lines54654754854955055155210 unmodified lines56356456556656756856954 unmodified lines624625626627628629630186 unmodified lines81781881982082182282312 unmodified lines83683783883984084184269 unmodified lines91291391491591691791827 unmodified lines{"cell_type": "code","source": ["# @title β Initialize\n","\n","import os\n","home_directory = '/content/'\n",56 unmodified lines"#------#\n","dot_dtype = torch.float32\n","dim = 768\n","ref = torch.zeros(dim).to(dtype = dot_dtype)"],"metadata": {"id": "TC5lMJrS1HCC","cellView": "form"},"execution_count": null,"outputs": []},{"cell_type": "markdown","source": ["The visualization has no effect on the output. It will only be used if you enable the 'Show encoding' checkbox"],"metadata": {"id": "OpOoRmaP3u2H"}},{"cell_type": "code","source": ["# @title β Define parameters for visalizing the reference in a 16x16 grid <br> (the visualization settings has no effect on output)\n","from PIL import Image, ImageDraw\n","SCALE = 0.0002 # @param {type:\"slider\", min:0.0001, max:0.001, step:0.00001}\n","ZERO_POINT = 100 # @param {type:\"slider\", min:0, max:300, step:1}\n","CELL_SIZE = 16\n","\n","BORDER_THICKNESS = 4\n","\n",31 unmodified lines"try: ref\n","except: ref = torch.zeros(dim).to(dtype = dot_dtype)\n","\n","image_size = 0.5 # @param {type:\"slider\", min:0, max:1, step:0.01}\n","show_encoding = True # @param {type:\"boolean\"}\n","#------#\n","if show_encoding:\n"," # create figure\n"," fig = plt.figure(figsize=(10*image_size, 10*image_size))\n",14 unmodified lines"print(f'Using settings SCALE = {SCALE} and ZERO_POINT = {ZERO_POINT} for visualizing the text_encoding')"],"metadata": {"id": "YDu8XlehhWID","cellView": "form"},"execution_count": null,"outputs": []},{"cell_type": "markdown","source": [7 unmodified lines{"cell_type": "code","source": ["\n","# @markdown π Write a text prompt (this will overwrite any savefile already stored)\n","NEW_ENCODING = '' # @param {type:'string' ,placeholder:'write a prompt'}\n","enable = True # @param {type:\"boolean\"}\n",98 unmodified lines"\n"],"metadata": {"id": "Oxi6nOyrUTAe"},"execution_count": null,"outputs": []10 unmodified lines{"cell_type": "code","source": ["\n","loaded_ref = False\n","try:\n"," ref\n",61 unmodified lines" #------#\n"],"metadata": {"id": "BwrEs5zVB0Sb"},"execution_count": null,"outputs": []10 unmodified lines{"cell_type": "code","source": ["\n","loaded_ref = False\n","try:\n"," ref\n",54 unmodified lines" #------#"],"metadata": {"id": "IqUsiQw2HU2C"},"execution_count": null,"outputs": []10 unmodified lines{"cell_type": "code","source": ["\n","loaded_ref = False\n","try:\n"," ref\n",58 unmodified lines" #------#"],"metadata": {"id": "I_-GOwFPKkha"},"execution_count": null,"outputs": []10 unmodified lines{"cell_type": "code","source": ["# @title β Save the reference\n","\n","loaded_ref = False\n","try:\n",54 unmodified lines{"cell_type": "code","source": ["# @title β CLIP Interrogator\n","LIST_SIZE = 1000 # @param {type:'number' , placeholder:'set how large the list should be'}\n","_START_AT = '0' # @param [\"0\", \"10000\", \"50000\"] {allow-input: true}\n","START_AT = 0\n",186 unmodified lines"image\n"],"metadata": {"id": "kOYZ8Ajn-DD8"},"execution_count": null,"outputs": []12 unmodified lines{"cell_type": "code","source": ["# @title β Evaluate similarities\n","%cd {output_folder_sims}\n","index = 0\n","for filename in os.listdir(output_folder_sims):\n",69 unmodified lines"plt.show()"],"metadata": {"id": "ln6DsZPG99ez"},"execution_count": null,"outputs": []27 unmodified lines2829303132333456 unmodified lines91929394959697989910010110210310410510631 unmodified lines13813914014114214314414 unmodified lines1591601611621631641651661671681691701711721731741751761771781797 unmodified lines18718818919019119219398 unmodified lines29229329429529629729829910 unmodified lines31031131231331431531661 unmodified lines37837938038138238338438510 unmodified lines39639739839940040140254 unmodified lines45745845946046146246346410 unmodified lines47547647747847948048158 unmodified lines54054154254354454554654710 unmodified lines55855956056156256356454 unmodified lines619620621622623624625186 unmodified lines81281381481581681781881912 unmodified lines83283383483583683783869 unmodified lines90890991091191291391491527 unmodified lines{"cell_type": "code","source": ["# @title β π Initialize\n","\n","import os\n","home_directory = '/content/'\n",56 unmodified lines"#------#\n","dot_dtype = torch.float32\n","dim = 768\n","ref = torch.zeros(dim).to(dtype = dot_dtype)\n","\n","# title β Define parameters for visalizing the reference in a 16x16 grid <br> (the visualization settings has no effect on output)\n","from PIL import Image, ImageDraw\n","SCALE = 0.0002 # param {type:\"slider\", min:0.0001, max:0.001, step:0.00001}\n","ZERO_POINT = 100 # param {type:\"slider\", min:0, max:300, step:1}\n","CELL_SIZE = 16\n","image_size = 0.5 # param {type:\"slider\", min:0, max:1, step:0.01}\n","show_encoding = False # param {type:\"boolean\"}\n","#------#\n","\n","BORDER_THICKNESS = 4\n","\n",31 unmodified lines"try: ref\n","except: ref = torch.zeros(dim).to(dtype = dot_dtype)\n","\n","\n","if show_encoding:\n"," # create figure\n"," fig = plt.figure(figsize=(10*image_size, 10*image_size))\n",14 unmodified lines"print(f'Using settings SCALE = {SCALE} and ZERO_POINT = {ZERO_POINT} for visualizing the text_encoding')"],"metadata": {"id": "TC5lMJrS1HCC","cellView": "form"},"execution_count": null,"outputs": []},{"cell_type": "markdown","source": ["The visualization has no effect on the output. It will only be used if you enable the 'Show encoding' checkbox"],"metadata": {"id": "OpOoRmaP3u2H"}},{"cell_type": "markdown","source": [7 unmodified lines{"cell_type": "code","source": ["# @title β π§© Create an encoding\n","# @markdown π Write a text prompt (this will overwrite any savefile already stored)\n","NEW_ENCODING = '' # @param {type:'string' ,placeholder:'write a prompt'}\n","enable = True # @param {type:\"boolean\"}\n",98 unmodified lines"\n"],"metadata": {"id": "Oxi6nOyrUTAe","cellView": "form"},"execution_count": null,"outputs": []10 unmodified lines{"cell_type": "code","source": ["# @title β π·π Use pre-encoded image+prompt pair\n","loaded_ref = False\n","try:\n"," ref\n",61 unmodified lines" #------#\n"],"metadata": {"id": "BwrEs5zVB0Sb","cellView": "form"},"execution_count": null,"outputs": []10 unmodified lines{"cell_type": "code","source": ["# @title β ππΌοΈ Load an image via URL\n","loaded_ref = False\n","try:\n"," ref\n",54 unmodified lines" #------#"],"metadata": {"id": "IqUsiQw2HU2C","cellView": "form"},"execution_count": null,"outputs": []10 unmodified lines{"cell_type": "code","source": ["# @title β ππΌοΈ Use an uploaded image as reference\n","loaded_ref = False\n","try:\n"," ref\n",58 unmodified lines" #------#"],"metadata": {"id": "I_-GOwFPKkha","cellView": "form"},"execution_count": null,"outputs": []10 unmodified lines{"cell_type": "code","source": ["# @title β πΎ Save the reference\n","\n","loaded_ref = False\n","try:\n",54 unmodified lines{"cell_type": "code","source": ["# @title β π΅οΈββοΈ Run the CLIP Interrogator\n","LIST_SIZE = 1000 # @param {type:'number' , placeholder:'set how large the list should be'}\n","_START_AT = '0' # @param [\"0\", \"10000\", \"50000\"] {allow-input: true}\n","START_AT = 0\n",186 unmodified lines"image\n"],"metadata": {"id": "kOYZ8Ajn-DD8","cellView": "form"},"execution_count": null,"outputs": []12 unmodified lines{"cell_type": "code","source": ["# @title β π Evaluate similarities\n","%cd {output_folder_sims}\n","index = 0\n","for filename in os.listdir(output_folder_sims):\n",69 unmodified lines"plt.show()"],"metadata": {"id": "ln6DsZPG99ez","cellView": "form"},"execution_count": null,"outputs": []
Google Colab Jupyter Notebooks/fusion_t2i_CLIP_interrogator.ipynb+39-42