File size: 11,264 Bytes
ddb7519 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/victorchall/EveryDream/blob/main/EveryDream_Tools.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"source": [
"#@title #Connect to Google Drive\n",
"from google.colab import drive\n",
"drive.mount('/content/drive')\n"
],
"metadata": {
"id": "Z_ZHfnQ52dg9"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "uJfwih4wAVgw"
},
"source": [
"# Please read the documentation here before you start.\n",
"\n",
"I suggest reading this doc before you connect to your runtime to avoid using credits or being charged while you figure it out.\n",
"\n",
"[Auto Captioning Readme](doc/AUTO_CAPTION.md)\n",
"\n",
"This notebook requires an Nvidia GPU instance. Any will do, you don't need anything power. As low as 4GB should be fine.\n",
"\n",
"Only colab has automatic file transfers at this time. If you are using another platform, you will need to manually download your output files."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "lWGx2LuU8Q_I"
},
"outputs": [],
"source": [
"#download repo\n",
"!git clone https://github.com/victorchall/EveryDream.git\n",
"# Set working directory\n",
"%cd EveryDream"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "RJxfSai-8pkD"
},
"outputs": [],
"source": [
"# install requirements\n",
"!pip install torch=='1.12.1+cu113' 'torchvision==0.13.1+cu113' --extra-index-url https://download.pytorch.org/whl/cu113\n",
"!pip install pandas>='1.3.5'\n",
"!git clone https://github.com/salesforce/BLIP scripts/BLIP\n",
"!pip install timm\n",
"!pip install fairscale=='0.4.4'\n",
"!pip install transformers=='4.19.2'\n",
"!pip install timm\n",
"!pip install aiofiles\n",
"!pip install colorama"
]
},
{
"cell_type": "markdown",
"source": [
"#Extract Frames from video\n",
"\n",
"Here we will use the folder input_vid and upload in the same way we did our images"
],
"metadata": {
"id": "huQSI8Y-Bboz"
}
},
{
"cell_type": "code",
"source": [
"!python /scripts/extract_video_frames.py \\\n",
"--vid_dir input_vid \\\n",
"--out_dir output/vid \\\n",
"--format png \\\n",
"--interval 10 "
],
"metadata": {
"id": "RDuBL4k8Avz-"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Move the extracted frames to the input directory for captions"
],
"metadata": {
"id": "iqcUzcRuCTLR"
}
},
{
"cell_type": "code",
"source": [
"!cp -r output/vid input"
],
"metadata": {
"id": "Uv8wAHSQAvrm"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "sbeUIVXJ-EVf"
},
"source": [
"# Upload your input images into the EveryDream/input folder\n",
"\n",
"![upload to input](https://github.com/victorchall/EveryDream/blob/main/demo/upload_images_caption.png?raw=1)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "bscWH13SAVgz"
},
"source": [
"## Please read the documentation for information on the parameters\n",
"\n",
"[Auto Captioning](doc/AUTO_CAPTION.md)\n",
"\n",
"*You cannot have commented lines between uncommented lines. If you uncomment a line below, move it above any other commented lines.*\n",
"\n",
"*!python must remain the first line.*\n",
"\n",
"Default params should work fairly well."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "4TAICahl-RPn"
},
"outputs": [],
"source": [
"!python scripts/auto_caption.py \\\n",
"--img_dir input \\\n",
"--out_dir output \\\n",
"#--format mrwho \\\n",
"#--min_length 34 \\\n",
"#--q_factor 1.3 \\\n",
"#--nucleus \\\n",
"\n",
"## mutiple files can be targeted in succession\n",
"\n",
"#!python scripts/auto_caption.py \\\n",
"#--img_dir input/subfolder \\\n",
"#--out_dir output/subfolder \\\n",
"#--format mrwho \\\n",
"#--min_length 34 \\\n",
"#--q_factor 1.3 \\\n",
"#--nucleus \\"
]
},
{
"cell_type": "markdown",
"source": [
"# Laion Downloader\n",
"\n",
"* --laion_dir: directory with laion parquet files, default is ./laion\n",
"\n",
"* --search_text: csv of words with AND logic, ex \\\"photo,man,dog\\\"\n",
"\n",
"* --out_dir: directory to download files to, ive defaulted this to inputs so they can be captioned \n",
"\n",
"* --log_dir: directory for logs, if ommitted will not log, logs may be large!\n",
"\n",
"* --column:column to search for matches, defaults is 'TEXT', but you could use 'URL' if you wanted\",\n",
"\n",
"* --limit: max number of matching images to download, warning: may be slightly imprecise due to concurrency and http errors, defaults is 100\n",
"\n",
"* --min_hw: min height AND width of image to download, default is 512\n",
" \n",
"* --force: forces a full download of all images, even if no search is provided, USE CAUTION!\n",
"\n",
"* --parquet_skip: skips the first n parquet files on disk, useful to resume\n",
" \n",
"* --verbose: additional logging of URL and TEXT \n",
" \n",
"* --test: skips downloading, for checking filters, use with \"--verbose\"\n"
],
"metadata": {
"id": "wY2f2LkPGSVa"
}
},
{
"cell_type": "code",
"source": [
"!python scripts/download_laion.py \\\n",
"--laion_dir ./laion \\\n",
"--search_text \"photo,man,dog\" \\\n",
"#--out_dir input \\\n",
"#--log_dir logs \\\n",
"#--column TEXT \\\n",
"#--limit 100 \\\n",
"#--min_hw 512 \\\n",
"#--force False \\\n",
"#--parquet_skip 0 \\\n",
"#--Verbose False \\\n",
"#--test not \\\n"
],
"metadata": {
"id": "cxw60TTmEy2C"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Here we can take our now captioned images and replace generic terms with our subjects\n",
"\n",
"* --find: will search for a word in this case man\n",
"\n",
"* --replace: will replace our found word with in this case bob smith\n",
"\n",
"* --append_only: this will allow us to add a tag at he end "
],
"metadata": {
"id": "EBdLelNpDjYc"
}
},
{
"cell_type": "code",
"source": [
"!python scripts/filename_replace.py \\\n",
"--img_dir output \\\n",
"--find \"man\" \\\n",
"--replace \"bob smith\""
],
"metadata": {
"id": "6Y1md3OHAvhw"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Now we can chose to create text files based on our file names, this is usefull for images with very long discriptions or tag list, windows has a limit of 256 characters, and files will not transfer correctly to a windows program if they are longer, moving these files in a zip is fine however and causes no issues\n"
],
"metadata": {
"id": "W0MspWmXJQuc"
}
},
{
"cell_type": "code",
"source": [
"!python scripts/createtxtfromfilename.py"
],
"metadata": {
"id": "BpvenvyQJr9b"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Compress our images "
],
"metadata": {
"id": "boVkDsiWJ_-P"
}
},
{
"cell_type": "code",
"source": [
"!python scripts/compress_img.py \\\n",
"--img_dir output \\\n",
"--out_dir output/compressed_images \\\n",
"--max_mp 1.5 \n",
"#--overwrite False \\\n",
"#--Quality 95 \\\n",
"#--noresize False \\\n",
"#--delete \\"
],
"metadata": {
"id": "F6QYfylhKAII"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "HBrWnu1C_lN9"
},
"source": [
"## Download your DataSet from EveryDream/output\n",
"\n",
"If you're on a colab you can use the cell below to push your output to your Gdrive."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ldW2sDLcAVgz"
},
"outputs": [],
"source": [
"\n",
"!mkdir /content/drive/MyDrive/Auto_Data_sets\n",
"!cp -r output/ /content/drive/MyDrive/Auto_Data_sets"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "B-HFqbP4AVgz"
},
"source": [
"## If not on colab/gdrive, the following will zip up your files for extraction\n",
"\n",
"You'll still need to use your runtime's own download feature to download the zip.\n",
"\n",
"![output zip](https://github.com/victorchall/EveryDream/blob/main/demo/output_zip.png?raw=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "SVa80mrKAVg0"
},
"outputs": [],
"source": [
"!pip install patool\n",
"\n",
"import patoolib\n",
"\n",
"!mkdir output/zip\n",
"\n",
"!zip -r output/zip/output.zip output"
]
}
],
"metadata": {
"colab": {
"provenance": [],
"machine_shape": "hm",
"include_colab_link": true
},
"kernelspec": {
"display_name": "Python 3.10.5 ('.venv': venv)",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.10.5"
},
"vscode": {
"interpreter": {
"hash": "faf4a6abb601e3a9195ce3e9620411ceec233a951446de834cdf28542d2d93b4"
}
},
"accelerator": "GPU",
"gpuClass": "standard"
},
"nbformat": 4,
"nbformat_minor": 0
}
|