diff --git "a/train_klein_SDNQ_test.ipynb" "b/train_klein_SDNQ_test.ipynb" new file mode 100644--- /dev/null +++ "b/train_klein_SDNQ_test.ipynb" @@ -0,0 +1,3812 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "OXGhsHQwWue_", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 839, + "referenced_widgets": [ + "5fb522aff98949e4ae7df3c20ed54703", + "28d8bb0a08104a25b440c5d5e8a9bd0f", + "b41a3725067646cf9a3c60ccefc64a97", + "8a09831ec0e84884b086df43f593ce11", + "f95662023f5e45c99c4ae704a8c539e9", + "4c06cd79dd7647658d93120b1bf42e28", + "ac3e92d8fb1944ff8d93d27092925b35", + "5f78e9e6854b4ff183f47f4b2a418608", + "9e103e65b32b4ad0abaa512f97b1ee3c", + "c078ccfc70c446a8b9ca506483ba1b0d", + "de393e6b05c14f589e05e2d79968cdfd", + "9c3333d7b393436da41d607f997a1b87", + "bd64e1b1949a45b28592e9449acd5d71", + "19d870948d314da5afc5010e889dc5ef", + "6fd66e23535e470f81d12cbe17ac42e7", + "6929567cfb864542b34f87bb17af6999", + "62b87f3dd7904b8293416dc3f4315517", + "14d35378a8ea40daabf7582c24141d21", + "423922fbba2d4c3aa9314ba4331bd0a7", + "ad61dce7a32f40c38c5c0235620d329b", + "331f1f508d23434fb5f6cf4bd37975cc", + "c8684352f6e449168a6cdaddeaa3acfe", + "491f54937819404d891578bc9cd659db", + "1da32d981bae4e6c8d4a384734ef39ef", + "534220ea214d4048a93000e942f7991d", + "10a62a86e8d04c9784f07ded08919a57", + "88346c0b0a374449a49911c395a6e001", + "756a0c170b034a30a14e0c52f299e8af", + "1c4361237a0940b08d91fe9c36ddb6ff", + "6b960da08bc64275b283ff2de3fbf864", + "eb57d6161b194692863969ca77a44f27", + "0a7a32e457f144b5b247559b5efd1855", + "ef720746be424a98944112b58cb0f00a", + "d74d70d64c43401d9636797bb5405ab9", + "dbeaa864d98645f083939873f2e1c64e", + "4d162183fe494f5e8589f2efcb3b709c", + "fed04e5e9f63488f97b780dc2599c0ab", + "49726df6963e484f80dccd9dad3f561d", + "b668d6c9da30444ba481764f58a1d613", + "aa4e6608fffd411ba0897d6106b4f551", + "1dce4b0d95d1452d982d9b6fb07c0f90", + "cfdd467912d54b2e8a72059ae9cacdc9", + "d0848635653141028bb665cf58ba412b", + "0a0e651f0f7a470fbca8662664c115fc", + "59b3aee270954902bba4c2bebec11683", + "1dbdd5a0e7ac47ccbedf8e7926abfe7c", + "f1738bed749c4414b566a963b2379b21", + "e5e2932e6e654e44a5b6f6d0b181d288", + "84a98b60fac441589d63bd86227dc17d", + "86a0b89247cc41bfa4bc751d2d8eff53", + "9861f89efbaa432c86ea381968338451", + "28155ec9896843528718308d0c47a839", + "7d96df2110f64ef4b572f2c8a57aaa43", + "6eb73b9d073742af9ddd59f54ff56841", + "a842e265159542fba4edb2f61a1b6a86" + ] + }, + "outputId": "072fe4f3-aab5-4b5d-e9ac-6a6324204fdf" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Mounted at /content/drive\n", + "🧹 Removing old diffusers...\n", + "πŸ”„ Installing latest diffusers...\n", + " Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", + " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", + " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", + " Building wheel for diffusers (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", + "Files removed: 6\n", + "βœ… Cell 1 complete!\n", + "Using zip from Drive: /content/drive/MyDrive/PROCESSED_klein_processed.zip\n", + "Widget upload is disabled. Using zip from Drive as specified in the previous cell.\n", + "Final zip_path for processing: /content/drive/MyDrive/PROCESSED_klein_processed.zip\n", + "βœ… Cell 2 settings loaded\n", + " Resolution: 1024Γ—1024\n", + " Use .txt prompts: False\n", + " Debug mode: False\n", + "\n", + "Now run Cell 3 (model load), then Cell 4 (inference)\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "Flax classes are deprecated and will be removed in Diffusers v1.0.0. We recommend migrating to PyTorch classes or pinning your version of Diffusers.\n", + "Flax classes are deprecated and will be removed in Diffusers v1.0.0. We recommend migrating to PyTorch classes or pinning your version of Diffusers.\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "πŸ“¦ Installing SDNQ...\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m104.0/104.0 kB\u001b[0m \u001b[31m5.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m509.1/509.1 kB\u001b[0m \u001b[31m27.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hπŸ”„ Loading model from: codeShare/FLUX.2-klein-AIO-SDNQ-4bit-dynamic\n" + ] + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "model_index.json: 0%| | 0.00/509 [00:00 /dev/null 2>&1\n", + "!rm -rf /usr/local/lib/python3.12/dist-packages/diffusers* ~/.cache/pip/*diffusers*\n", + "\n", + "print(\"πŸ”„ Installing latest diffusers...\")\n", + "!pip install -q git+https://github.com/huggingface/diffusers.git --force-reinstall --no-deps\n", + "!python -m pip cache purge\n", + "\n", + "print(\"βœ… Cell 1 complete!\")\n", + "\n", + "#-----#\n", + "\n", + "#@title Set path to zip file on your drive , and set klein edit prompt\n", + "upload_from_widget = False #@param {type:'boolean'}\n", + "input_zip_path = '/content/drive/MyDrive/PROCESSED_klein_processed.zip' #@param {type:'string'}\n", + "edit_prompt = 'remove the white background. the background is dark gray. ' #@param {type:'string'}\n", + "\n", + "# Initialize zip_path; it will be set definitively by this cell or the next.\n", + "zip_path = None\n", + "\n", + "if not upload_from_widget:\n", + " zip_path = input_zip_path\n", + " print(f\"Using zip from Drive: {zip_path}\")\n", + "else:\n", + " print(\"Widget upload enabled. Please run the next cell to upload your files.\")\n", + "\n", + "#---#\n", + "#@title Upload files via widget\n", + "import os\n", + "from google.colab import files\n", + "import zipfile\n", + "import shutil\n", + "\n", + "if upload_from_widget:\n", + " print(\"Please upload your zip file or individual image files now.\")\n", + " uploaded = files.upload()\n", + "\n", + " if not uploaded:\n", + " raise ValueError(\"No files uploaded. Please upload a zip file or images.\")\n", + "\n", + " if len(uploaded) == 1 and list(uploaded.keys())[0].endswith('.zip'):\n", + " # If a single zip file is uploaded\n", + " uploaded_filename = list(uploaded.keys())[0]\n", + " shutil.move(uploaded_filename, '/content/' + uploaded_filename)\n", + " zip_path = '/content/' + uploaded_filename\n", + " print(f\"Using uploaded zip file: {zip_path}\")\n", + " else:\n", + " # If multiple image files are uploaded, create a zip file\n", + " temp_img_dir = '/content/uploaded_images_temp'\n", + " os.makedirs(temp_img_dir, exist_ok=True)\n", + "\n", + " image_count = 0\n", + " for fname, content in uploaded.items():\n", + " if fname.lower().endswith(('.png', '.jpg', '.jpeg', '.webp', '.gif')):\n", + " with open(os.path.join(temp_img_dir, fname), 'wb') as f:\n", + " f.write(content)\n", + " image_count += 1\n", + " else:\n", + " print(f\"Skipping non-image file: {fname}\")\n", + "\n", + " if image_count == 0:\n", + " raise ValueError(\"No valid image files uploaded. Please upload images.\")\n", + "\n", + " zip_path = '/content/uploaded_images.zip'\n", + " with zipfile.ZipFile(zip_path, 'w') as zf:\n", + " for root, _, files_in_dir in os.walk(temp_img_dir):\n", + " for file_in_dir in files_in_dir:\n", + " zf.write(os.path.join(root, file_in_dir), os.path.basename(file_in_dir))\n", + " shutil.rmtree(temp_img_dir)\n", + " print(f\"Created zip from {image_count} uploaded images: {zip_path}\")\n", + "else:\n", + " print(\"Widget upload is disabled. Using zip from Drive as specified in the previous cell.\")\n", + "\n", + "print(f\"Final zip_path for processing: {zip_path}\")\n", + "\n", + "#-----#\n", + "\n", + "# =============================================================================\n", + "#@markdown # **CELL 2**: Fixed settings (resolution + options)\n", + "# =============================================================================\n", + "\n", + "resolution = '1024 x 1024 (Square)' #@param [\"1024 x 1024 (Square)\", \"512 x 1024 (Portrait)\", \"768 x 1024 (Slight Portrait)\", \"1536 x 1024 (Landscape)\", \"2048 x 1024 (Wide Landscape)\"] {type:\"string\"}\n", + "use_txt_prompts = False #@param {type:\"boolean\"}\n", + "debug = False #@param {type:\"boolean\"}\n", + "\n", + "res_map = {\n", + " \"1024 x 1024 (Square)\": (1024, 1024),\n", + " \"512 x 1024 (Portrait)\": (512, 1024),\n", + " \"768 x 1024 (Slight Portrait)\": (768, 1024),\n", + " \"1536 x 1024 (Landscape)\": (1536, 1024),\n", + " \"2048 x 1024 (Wide Landscape)\": (2048, 1024)\n", + "}\n", + "target_width, target_height = res_map[resolution]\n", + "\n", + "print(\"βœ… Cell 2 settings loaded\")\n", + "print(f\" Resolution: {target_width}Γ—{target_height}\")\n", + "print(f\" Use .txt prompts: {use_txt_prompts}\")\n", + "print(f\" Debug mode: {debug}\")\n", + "print(\"\\nNow run Cell 3 (model load), then Cell 4 (inference)\")\n", + "\n", + "#----#\n", + "\n", + "# =============================================================================\n", + "#@markdown # **CELL 3B**: Load SDNQ MODEL + Fixed Text Encoder (GPU Embedding)\n", + "# =============================================================================\n", + "\n", + "import torch\n", + "import gc\n", + "import os\n", + "from diffusers import Flux2KleinPipeline\n", + "\n", + "print(\"πŸ“¦ Installing SDNQ...\")\n", + "!pip install -q sdnq\n", + "\n", + "from sdnq.common import use_torch_compile as triton_is_available\n", + "from sdnq.loader import apply_sdnq_options_to_model\n", + "\n", + "gc.collect()\n", + "torch.cuda.empty_cache()\n", + "\n", + "# =========================================================\n", + "# πŸ”₯ LOAD MODEL ON CPU FIRST (Safe loading)\n", + "# =========================================================\n", + "MODEL_ID = \"codeShare/FLUX.2-klein-AIO-SDNQ-4bit-dynamic\" #@param ['codeShare/Flux-Klein-SDNQ-4bit','codeShare/FLUX.2-klein-AIO-SDNQ-4bit-dynamic', 'codeShare/unstableRevolution_SDNQ']\n", + "\n", + "print(f\"πŸ”„ Loading model from: {MODEL_ID}\")\n", + "\n", + "pipe = Flux2KleinPipeline.from_pretrained(\n", + " MODEL_ID,\n", + " torch_dtype=torch.float16,\n", + " low_cpu_mem_usage=True,\n", + " device_map=\"cpu\"\n", + ")\n", + "\n", + "print(\"βœ… Base pipeline loaded on CPU\")\n", + "\n", + "# =========================================================\n", + "# πŸ”₯ COMPUTE FIXED EMBEDDING ON GPU\n", + "# =========================================================\n", + "edit_prompt = 'remove the white background. the background is dark gray. '\n", + "\n", + "print(f\"πŸ”€ Encoding fixed prompt on GPU: '{edit_prompt}'\")\n", + "\n", + "# Temporarily move text_encoder to GPU for faster embedding computation\n", + "pipe.text_encoder = pipe.text_encoder.to(\"cuda\")\n", + "\n", + "with torch.no_grad():\n", + " prompt_embeds, pooled_prompt_embeds = pipe.encode_prompt(\n", + " prompt=edit_prompt,\n", + " num_images_per_prompt=1,\n", + " device=\"cuda\",\n", + " max_sequence_length=512,\n", + " )\n", + "\n", + "# Move embedding back to CPU for storage (lower memory)\n", + "prompt_embeds = prompt_embeds.cpu()\n", + "if pooled_prompt_embeds is not None:\n", + " pooled_prompt_embeds = pooled_prompt_embeds.cpu()\n", + "\n", + "print(\"βœ… Embedding computed on GPU. Shape:\", prompt_embeds.shape)\n", + "\n", + "# =========================================================\n", + "# πŸ”₯ UNLOAD ORIGINAL TEXT ENCODER + REPLACE WITH FIXED ONE\n", + "# =========================================================\n", + "# Delete original text encoder to free VRAM\n", + "if hasattr(pipe, 'text_encoder'):\n", + " del pipe.text_encoder\n", + " gc.collect()\n", + " torch.cuda.empty_cache()\n", + "\n", + "class FixedEmbeddingEncoder:\n", + " def __init__(self, prompt_embeds, pooled=None):\n", + " self.prompt_embeds = prompt_embeds\n", + " self.pooled_prompt_embeds = pooled\n", + "\n", + " def __call__(self, *args, **kwargs):\n", + " # Return object that mimics what the pipeline expects\n", + " class DummyOutput:\n", + " last_hidden_state = self.prompt_embeds\n", + " # Add pooled_prompt_embeds if pipeline accesses it\n", + " pooled_prompt_embeds = self.pooled_prompt_embeds\n", + " return DummyOutput()\n", + "\n", + " def to(self, device=None, *args, **kwargs):\n", + " return self\n", + " def cuda(self): return self\n", + " def cpu(self): return self\n", + "\n", + "# Replace with fixed embedding\n", + "pipe.text_encoder = FixedEmbeddingEncoder(prompt_embeds, pooled_prompt_embeds)\n", + "\n", + "# Clean tokenizer\n", + "if hasattr(pipe, \"tokenizer\"):\n", + " pipe.tokenizer = None\n", + "\n", + "print(\"βœ… Original text_encoder fully unloaded and replaced with fixed embedding\")\n", + "\n", + "# =========================================================\n", + "# πŸ”₯ SDNQ OPTIMIZATIONS + MEMORY SETTINGS\n", + "# =========================================================\n", + "if torch.cuda.is_available() and triton_is_available:\n", + " pipe.transformer = apply_sdnq_options_to_model(\n", + " pipe.transformer,\n", + " use_quantized_matmul=True\n", + " )\n", + " print(\" βœ… SDNQ quantized matmul applied to transformer\")\n", + "\n", + "# Enable memory optimizations\n", + "pipe.enable_model_cpu_offload()\n", + "pipe.vae.enable_slicing()\n", + "pipe.vae.enable_tiling()\n", + "\n", + "gc.collect()\n", + "torch.cuda.empty_cache()\n", + "\n", + "print(\"βœ… CELL 3B COMPLETE - Fixed embedding computed on GPU\")\n", + "print(\"VRAM usage:\", round(torch.cuda.memory_allocated() / 1e9, 2), \"GB\")\n", + "print(\"πŸ‘‰ Original text_encoder has been unloaded.\")\n", + "\n", + "#-----#\n", + "\n", + "# =============================================================================\n", + "#@markdown # **CELL 4B**: Convert to SDNQ Quantized Training Model\n", + "# =============================================================================\n", + "\n", + "from sdnq.training import sdnq_training_post_load_quant, convert_sdnq_model_to_training\n", + "from sdnq.common import use_torch_compile as triton_is_available\n", + "import torch\n", + "import gc\n", + "\n", + "gc.collect()\n", + "torch.cuda.empty_cache()\n", + "\n", + "print(\"πŸ”„ Converting transformer to SDNQ training mode...\")\n", + "\n", + "# Option 1: If the loaded model is already SDNQ-quantized, use convert_...\n", + "quantized_model = convert_sdnq_model_to_training(\n", + " pipe.transformer, # Usually the heaviest part\n", + " quantized_matmul_dtype=\"int8\",\n", + " use_grad_ckpt=True, # Recommended for training\n", + " use_quantized_matmul=triton_is_available,\n", + " use_stochastic_rounding=True,\n", + " dequantize_fp32=True,\n", + ")\n", + "\n", + "# Option 2: Alternative - post-load quant (use one or the other)\n", + "# quantized_model = sdnq_training_post_load_quant(\n", + "# pipe.transformer,\n", + "# weights_dtype=\"uint8\",\n", + "# quantized_matmul_dtype=\"int8\",\n", + "# group_size=32,\n", + "# svd_rank=32,\n", + "# svd_steps=8,\n", + "# use_svd=False,\n", + "# use_grad_ckpt=True,\n", + "# use_quantized_matmul=triton_is_available,\n", + "# use_static_quantization=True,\n", + "# use_stochastic_rounding=True,\n", + "# dequantize_fp32=True,\n", + "# non_blocking=False,\n", + "# add_skip_keys=True,\n", + "# quantization_device=\"cuda\",\n", + "# return_device=\"cuda\",\n", + "# modules_to_not_convert=[\"correction_coefs\", \"prediction_coefs\", \"lm_head\", \"embedding_projection\"],\n", + "# )\n", + "\n", + "# Replace in pipeline\n", + "pipe.transformer = quantized_model\n", + "\n", + "# Move to training mode\n", + "pipe.transformer.train()\n", + "\n", + "# Optional: quantized optimizer later when you set up training loop\n", + "# from sdnq.optim import AdamW\n", + "# optimizer = AdamW(pipe.transformer.parameters(), ...)\n", + "\n", + "gc.collect()\n", + "torch.cuda.empty_cache()\n", + "\n", + "print(\"βœ… CELL 4B COMPLETE - Transformer converted to SDNQ training model\")\n", + "print(\"VRAM:\", round(torch.cuda.memory_allocated() / 1e9, 2), \"GB\")\n", + "print(\"Model is ready for training with fixed edit prompt embedding.\")\n", + "\n", + "#----#\n", + "\n", + "# ------------------- CLEANUP -------------------\n", + "print(\"🧹 Cleaning up before training...\")\n", + "\n", + "gc.collect()\n", + "torch.cuda.empty_cache()\n", + "torch.cuda.reset_peak_memory_stats()\n", + "\n" + ] + }, + { + "cell_type": "code", + "source": [ + "# =============================================================================\n", + "# πŸ”₯ CELL 5B: SINGLE IMAGE TRAINING (FINAL FINAL FIX)\n", + "# =============================================================================\n", + "\n", + "import torch\n", + "import torch.nn.functional as F\n", + "from torchvision import transforms\n", + "from PIL import Image\n", + "import gc\n", + "from tqdm import tqdm\n", + "import os\n", + "\n", + "from sdnq.optim import AdamW\n", + "\n", + "device = \"cuda\"\n", + "\n", + "# =========================================================\n", + "# πŸ“· LOAD IMAGE\n", + "# =========================================================\n", + "\n", + "image_path = \"/content/drive/MyDrive/test_image.jpg\"\n", + "\n", + "image = Image.open(image_path).convert(\"RGB\")\n", + "\n", + "transform = transforms.Compose([\n", + " transforms.Resize((target_height, target_width)),\n", + " transforms.CenterCrop((target_height, target_width)),\n", + " transforms.ToTensor(),\n", + " transforms.Normalize([0.5], [0.5])\n", + "])\n", + "\n", + "image = transform(image).unsqueeze(0).to(device, dtype=torch.float16)\n", + "print(\"πŸ“· Loaded training image:\", image.shape)\n", + "\n", + "# =========================================================\n", + "# βš™οΈ SETTINGS\n", + "# =========================================================\n", + "\n", + "steps = 1000\n", + "lr = 1e-5\n", + "save_every = 200\n", + "\n", + "# =========================================================\n", + "# πŸ”§ OPTIMIZER\n", + "# =========================================================\n", + "\n", + "optimizer = AdamW(pipe.transformer.parameters(), lr=lr)\n", + "pipe.transformer.train()\n", + "\n", + "prompt_embeds_gpu = prompt_embeds.to(device)\n", + "\n", + "# =========================================================\n", + "# πŸ”§ BUILD STATIC txt_ids (once)\n", + "# =========================================================\n", + "\n", + "seq_len = prompt_embeds_gpu.shape[1]\n", + "txt_ids = torch.arange(seq_len, device=device).unsqueeze(0) # [1, seq_len]\n", + "\n", + "# =========================================================\n", + "# πŸ”₯ TRAINING LOOP\n", + "# =========================================================\n", + "\n", + "pbar = tqdm(range(steps))\n", + "\n", + "for step in pbar:\n", + "\n", + " # ----------------------------------------\n", + " # πŸ”Ή Encode β†’ latents\n", + " # ----------------------------------------\n", + " with torch.no_grad():\n", + " latents = pipe.vae.encode(image).latent_dist.sample()\n", + "\n", + " B, C, H, W = latents.shape\n", + "\n", + " # ----------------------------------------\n", + " # πŸ”Ή Build img_ids (CRITICAL FIX)\n", + " # ----------------------------------------\n", + " # create 2D grid of positions\n", + " y, x = torch.meshgrid(\n", + " torch.arange(H, device=device),\n", + " torch.arange(W, device=device),\n", + " indexing=\"ij\"\n", + " )\n", + "\n", + " img_ids = torch.stack([y, x], dim=-1) # [H, W, 2]\n", + " img_ids = img_ids.view(1, H * W, 2) # [1, tokens, 2]\n", + "\n", + " # ----------------------------------------\n", + " # πŸ”Ή Sample noise + t\n", + " # ----------------------------------------\n", + " noise = torch.randn_like(latents)\n", + "\n", + " t = torch.rand((1,), device=device, dtype=torch.float16)\n", + " t_broadcast = t.view(1, 1, 1, 1)\n", + "\n", + " # Flow interpolation\n", + " noisy_latents = (1 - t_broadcast) * latents + t_broadcast * noise\n", + " target = noise - latents\n", + "\n", + " # ----------------------------------------\n", + " # πŸ”Ή Forward\n", + " # ----------------------------------------\n", + " model_pred = pipe.transformer(\n", + " hidden_states=noisy_latents,\n", + " timestep=t,\n", + " encoder_hidden_states=prompt_embeds_gpu,\n", + " img_ids=img_ids,\n", + " txt_ids=txt_ids,\n", + " return_dict=False\n", + " )[0]\n", + "\n", + " # ----------------------------------------\n", + " # πŸ”Ή LOSS\n", + " # ----------------------------------------\n", + " loss = F.mse_loss(model_pred.float(), target.float(), reduction=\"mean\")\n", + "\n", + " loss.backward()\n", + "\n", + " # ----------------------------------------\n", + " # πŸ”Ή STEP\n", + " # ----------------------------------------\n", + " optimizer.step()\n", + " optimizer.zero_grad(set_to_none=True)\n", + "\n", + " torch.nn.utils.clip_grad_norm_(pipe.transformer.parameters(), 1.0)\n", + "\n", + " # ----------------------------------------\n", + " # πŸ”Ή LOGGING\n", + " # ----------------------------------------\n", + " pbar.set_postfix(loss=loss.item())\n", + "\n", + " # ----------------------------------------\n", + " # πŸ’Ύ SAVE\n", + " # ----------------------------------------\n", + " if step % save_every == 0 and step > 0:\n", + " save_path = f\"/content/drive/MyDrive/sdnq_single_image_{step}\"\n", + " os.makedirs(save_path, exist_ok=True)\n", + "\n", + " pipe.transformer.save_pretrained(save_path)\n", + " print(f\"\\nπŸ’Ύ Saved checkpoint at step {step}\")\n", + "\n", + " # ----------------------------------------\n", + " # 🧹 CLEANUP\n", + " # ----------------------------------------\n", + " if step % 20 == 0:\n", + " gc.collect()\n", + " torch.cuda.empty_cache()\n", + "\n", + "print(\"βœ… TRAINING COMPLETE\")" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 391 + }, + "id": "2mK44niN52a3", + "outputId": "9a38b0be-f00e-4d43-9ca8-bb49716d027e" + }, + "execution_count": 6, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "πŸ“· Loaded training image: torch.Size([1, 3, 1024, 1024])\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + " 0%| | 0/1000 [00:02\u001b[0;34m()\u001b[0m\n\u001b[1;32m 101\u001b[0m \u001b[0;31m# πŸ”Ή Forward\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 102\u001b[0m \u001b[0;31m# ----------------------------------------\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 103\u001b[0;31m model_pred = pipe.transformer(\n\u001b[0m\u001b[1;32m 104\u001b[0m \u001b[0mhidden_states\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnoisy_latents\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 105\u001b[0m \u001b[0mtimestep\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mt\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.12/dist-packages/torch/nn/modules/module.py\u001b[0m in \u001b[0;36m_wrapped_call_impl\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1774\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_compiled_call_impl\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# type: ignore[misc]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1775\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1776\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call_impl\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\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 1777\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1778\u001b[0m \u001b[0;31m# torchrec tests the code consistency with the following code\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py\u001b[0m in \u001b[0;36m_call_impl\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1785\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0m_global_backward_pre_hooks\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0m_global_backward_hooks\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1786\u001b[0m or _global_forward_hooks or _global_forward_pre_hooks):\n\u001b[0;32m-> 1787\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mforward_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\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 1788\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1789\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/accelerate/hooks.py\u001b[0m in \u001b[0;36mnew_forward\u001b[0;34m(module, *args, **kwargs)\u001b[0m\n\u001b[1;32m 190\u001b[0m \u001b[0moutput\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodule\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_old_forward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 191\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 192\u001b[0;31m \u001b[0moutput\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodule\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_old_forward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\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 193\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mmodule\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_hf_hook\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpost_forward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodule\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutput\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 194\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/diffusers/utils/peft_utils.py\u001b[0m in \u001b[0;36mwrapper\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 313\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 314\u001b[0m \u001b[0;31m# Execute the forward pass\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 315\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mforward_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\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 316\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 317\u001b[0m \u001b[0;32mfinally\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.12/dist-packages/diffusers/models/transformers/transformer_flux2.py\u001b[0m in \u001b[0;36mforward\u001b[0;34m(self, hidden_states, encoder_hidden_states, timestep, img_ids, txt_ids, guidance, joint_attention_kwargs, return_dict, kv_cache, kv_cache_mode, num_ref_tokens, ref_fixed_timestep)\u001b[0m\n\u001b[1;32m 1272\u001b[0m \u001b[0mtxt_ids\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtxt_ids\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1273\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1274\u001b[0;31m \u001b[0mimage_rotary_emb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpos_embed\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimg_ids\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 1275\u001b[0m \u001b[0mtext_rotary_emb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpos_embed\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtxt_ids\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1276\u001b[0m concat_rotary_emb = (\n", + "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py\u001b[0m in \u001b[0;36m_wrapped_call_impl\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1774\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_compiled_call_impl\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# type: ignore[misc]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1775\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1776\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call_impl\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\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 1777\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1778\u001b[0m \u001b[0;31m# torchrec tests the code consistency with the following code\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py\u001b[0m in \u001b[0;36m_call_impl\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1785\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0m_global_backward_pre_hooks\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0m_global_backward_hooks\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1786\u001b[0m or _global_forward_hooks or _global_forward_pre_hooks):\n\u001b[0;32m-> 1787\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mforward_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\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 1788\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1789\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.12/dist-packages/diffusers/models/transformers/transformer_flux2.py\u001b[0m in \u001b[0;36mforward\u001b[0;34m(self, ids)\u001b[0m\n\u001b[1;32m 967\u001b[0m cos, sin = get_1d_rotary_pos_embed(\n\u001b[1;32m 968\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maxes_dim\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\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[0;32m--> 969\u001b[0;31m \u001b[0mpos\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m...\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mi\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[0m\u001b[1;32m 970\u001b[0m \u001b[0mtheta\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtheta\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 971\u001b[0m \u001b[0mrepeat_interleave_real\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[0;31mIndexError\u001b[0m: index 2 is out of bounds for dimension 1 with size 2" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "# Run Klein finetune (select which one to use)" + ], + "metadata": { + "id": "6UhKYCWzPyrm" + } + }, + { + "cell_type": "markdown", + "source": [ + "# OLD CODE" + ], + "metadata": { + "id": "Mj8UDNOyqdKL" + } + }, + { + "cell_type": "code", + "source": [ + "# =============================================================================\n", + "#@markdown # **CELL 4**: MULTI-IMAGE INFERENCE (Klein Edit with custom/gray reference)\n", + "# =============================================================================\n", + "import zipfile\n", + "import os\n", + "import shutil\n", + "import glob\n", + "from PIL import Image, ImageDraw\n", + "import torch\n", + "import gc\n", + "import datetime\n", + "from google.colab import files\n", + "\n", + "#edit_prompt = 'remove the background. the background is gray.' #@param {type:\"string\"}\n", + "#zip_path = '/content/drive/MyDrive/aiotest.zip' #@param {type:\"string\"}\n", + "\n", + "upload_custom_reference = False #@param {type:\"boolean\"}\n", + "max_image_dimension = 2048 #@param {type:\"slider\", min:512, max:4096, step:256}\n", + "add_gray_corners = False #@param {type:\"boolean\"}\n", + "gray_square_size = 50 #@param {type:\"slider\", min:10, max:200, step:10}\n", + "\n", + "# ================= NEW CONTROLS =================\n", + "save_to_drive_every_n = False #@param {type:\"boolean\"}\n", + "save_every_n = 30 #@param {type:\"slider\", min:1, max:100, step:1}\n", + "# ===============================================\n", + "\n", + "output_folder = '/content/edited_images_multi'\n", + "checkpoint_folder = '/content/drive/MyDrive/klein_checkpoints'\n", + "\n", + "print(\"🧹 Clearing old temporary folders...\")\n", + "for p in ['/content/input_images', output_folder]:\n", + " if os.path.exists(p):\n", + " shutil.rmtree(p)\n", + "\n", + "os.makedirs(output_folder, exist_ok=True)\n", + "os.makedirs(checkpoint_folder, exist_ok=True)\n", + "\n", + "# ====================== Unzip ======================\n", + "print(f\"πŸ“¦ Unzipping: {zip_path}...\")\n", + "with zipfile.ZipFile(zip_path, 'r') as z:\n", + " z.extractall('/content/input_images')\n", + "\n", + "image_files = sorted(glob.glob('/content/input_images/*.*'))\n", + "image_files = [f for f in image_files if f.lower().endswith(('.png', '.jpg', '.jpeg', '.webp'))]\n", + "print(f\"Found {len(image_files)} images.\")\n", + "\n", + "# ====================== PROMPT MAP ======================\n", + "prompt_map = {}\n", + "txt_count = 0\n", + "for img_path in image_files:\n", + " base = os.path.splitext(os.path.basename(img_path))[0]\n", + " txt_path = os.path.join('/content/input_images', f\"{base}.txt\")\n", + "\n", + " if use_txt_prompts and os.path.exists(txt_path):\n", + " with open(txt_path, 'r', encoding='utf-8') as f:\n", + " prompt_map[img_path] = f.read().strip()\n", + " txt_count += 1\n", + " else:\n", + " prompt_map[img_path] = None\n", + "\n", + "print(f\"Found {txt_count} matching .txt files\")\n", + "\n", + "# ====================== REFERENCE IMAGE ======================\n", + "uploaded_reference_filepath = None\n", + "reference_image_to_pair = None\n", + "\n", + "if upload_custom_reference:\n", + " print(\"Please upload your reference image now.\")\n", + " uploaded_files = files.upload()\n", + " if uploaded_files:\n", + " uploaded_reference_filepath = list(uploaded_files.keys())[0]\n", + " reference_image_to_pair = Image.open(uploaded_reference_filepath).convert(\"RGB\")\n", + "else:\n", + " reference_image_to_pair = Image.new(\"RGB\", (target_width, target_height), \"#181818\")\n", + "\n", + "if uploaded_reference_filepath and os.path.exists(uploaded_reference_filepath):\n", + " os.remove(uploaded_reference_filepath)\n", + "\n", + "# ====================== HELPERS ======================\n", + "def add_corner_squares(image: Image.Image, square_size: int, color=(24, 24, 24)):\n", + " img_copy = image.copy()\n", + " draw = ImageDraw.Draw(img_copy)\n", + " w, h = img_copy.size\n", + " draw.rectangle([(0, 0), (square_size, square_size)], fill=color)\n", + " draw.rectangle([(w-square_size, 0), (w, square_size)], fill=color)\n", + " draw.rectangle([(0, h-square_size), (square_size, h)], fill=color)\n", + " draw.rectangle([(w-square_size, h-square_size), (w, h)], fill=color)\n", + " return img_copy\n", + "\n", + "def save_checkpoint(batch_files, checkpoint_id):\n", + " if not save_to_drive_every_n:\n", + " return\n", + " zip_path = f\"{checkpoint_folder}/checkpoint_{checkpoint_id}.zip\"\n", + " temp_folder = f\"{checkpoint_folder}/tmp_{checkpoint_id}\"\n", + " os.makedirs(temp_folder, exist_ok=True)\n", + "\n", + " for f in batch_files:\n", + " shutil.copy(f, temp_folder)\n", + "\n", + " shutil.make_archive(zip_path.replace('.zip',''), 'zip', temp_folder)\n", + " shutil.rmtree(temp_folder)\n", + " print(f\"πŸ’Ύ Saved checkpoint: {zip_path}\")\n", + "\n", + "# ====================== INFERENCE ======================\n", + "print(f\"\\nπŸš€ Starting batch on {len(image_files)} images...\")\n", + "\n", + "batch_outputs = []\n", + "checkpoint_id = 0\n", + "\n", + "for i, img_path in enumerate(image_files):\n", + " filename = os.path.basename(img_path)\n", + "\n", + " gc.collect()\n", + " torch.cuda.empty_cache()\n", + "\n", + " input_image = Image.open(img_path).convert(\"RGB\")\n", + "\n", + " # resize\n", + " if max(input_image.width, input_image.height) > max_image_dimension:\n", + " aspect = input_image.width / input_image.height\n", + " if input_image.width > input_image.height:\n", + " input_image = input_image.resize(\n", + " (max_image_dimension, int(max_image_dimension / aspect)),\n", + " Image.LANCZOS\n", + " )\n", + " else:\n", + " input_image = input_image.resize(\n", + " (int(max_image_dimension * aspect), max_image_dimension),\n", + " Image.LANCZOS\n", + " )\n", + "\n", + " if add_gray_corners:\n", + " input_image = add_corner_squares(input_image, gray_square_size)\n", + "\n", + " reference_images = [input_image, reference_image_to_pair]\n", + "\n", + " current_prompt = (\n", + " prompt_map[img_path]\n", + " if use_txt_prompts and prompt_map[img_path] is not None\n", + " else edit_prompt\n", + " )\n", + "\n", + " result = pipe(\n", + " prompt=current_prompt,\n", + " image=reference_images,\n", + " height=target_height,\n", + " width=target_width,\n", + " guidance_scale=1.0,\n", + " num_inference_steps=4,\n", + " generator=torch.Generator(\"cuda\").manual_seed(42),\n", + " output_type=\"pil\",\n", + " ).images[0]\n", + "\n", + " out_path = os.path.join(output_folder, f\"edited_{filename}\")\n", + " result.save(out_path)\n", + " batch_outputs.append(out_path)\n", + "\n", + " print(f\"[{i+1}/{len(image_files)}] saved β†’ {out_path}\")\n", + "\n", + " # ====================== SAVE EVERY N ======================\n", + " if save_to_drive_every_n and (len(batch_outputs) >= save_every_n):\n", + " checkpoint_id += 1\n", + " save_checkpoint(batch_outputs, checkpoint_id)\n", + " batch_outputs = [] # reset buffer\n", + "\n", + "# ====================== FINAL FLUSH SAVE ======================\n", + "if save_to_drive_every_n and len(batch_outputs) > 0:\n", + " checkpoint_id += 1\n", + " save_checkpoint(batch_outputs, checkpoint_id)\n", + "\n", + "print(\"\\nβœ… BATCH COMPLETE!\")\n", + "\n", + "# ====================== FINAL ZIP ======================\n", + "timestamp = datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")\n", + "final_zip = f\"/content/drive/MyDrive/klein_edited_{timestamp}.zip\"\n", + "\n", + "print(f\"πŸ“¦ Final zip β†’ {final_zip}\")\n", + "shutil.make_archive(final_zip.replace('.zip',''), 'zip', output_folder)\n", + "\n", + "print(\"🎯 DONE\")" + ], + "metadata": { + "cellView": "form", + "id": "Q14frr2en161" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Cell 4 version with Encrypt (wip)" + ], + "metadata": { + "id": "TEupY-WNeMHu" + } + }, + { + "cell_type": "code", + "source": [ + "# =============================================================================\n", + "#@markdown # **CELL 4 INFERENCE\n", + "# =============================================================================\n", + "import zipfile\n", + "import os\n", + "import shutil\n", + "import glob\n", + "from PIL import Image\n", + "import torch\n", + "import gc\n", + "import datetime\n", + "import hashlib\n", + "import io\n", + "\n", + "!pip install -q pynacl\n", + "from nacl.secret import SecretBox\n", + "from nacl.utils import random\n", + "\n", + "# ================= SETTINGS =================\n", + "encryption_password = \"banana\" #@param {type:\"string\"}\n", + "\n", + "upload_custom_reference = False #@param {type:\"boolean\"}\n", + "max_image_dimension = 2048\n", + "\n", + "output_folder = '/content/encrypted_outputs'\n", + "\n", + "# ================= CLEAN =================\n", + "for p in ['/content/input_images', output_folder]:\n", + " if os.path.exists(p):\n", + " shutil.rmtree(p)\n", + "\n", + "os.makedirs(output_folder, exist_ok=True)\n", + "\n", + "# ================= KEY =================\n", + "def derive_key(password):\n", + " return hashlib.sha256(password.encode()).digest()\n", + "\n", + "box = SecretBox(derive_key(encryption_password))\n", + "\n", + "def pil_to_bytes(img):\n", + " buf = io.BytesIO()\n", + " img.save(buf, format=\"JPEG\", quality=95)\n", + " return buf.getvalue()\n", + "\n", + "def encrypt_bytes(data):\n", + " nonce = random(SecretBox.NONCE_SIZE)\n", + " enc = box.encrypt(data, nonce)\n", + " return enc.nonce + enc.ciphertext\n", + "\n", + "# ================= UNZIP =================\n", + "print(f\"πŸ“¦ Unzipping: {zip_path}\")\n", + "with zipfile.ZipFile(zip_path, 'r') as z:\n", + " z.extractall('/content/input_images')\n", + "\n", + "image_files = sorted(glob.glob('/content/input_images/*.*'))\n", + "image_files = [f for f in image_files if f.lower().endswith(('.png','.jpg','.jpeg','.webp'))]\n", + "\n", + "print(f\"Found {len(image_files)} images\")\n", + "\n", + "# ================= REFERENCE =================\n", + "if upload_custom_reference:\n", + " from google.colab import files\n", + " uploaded = files.upload()\n", + " ref_path = list(uploaded.keys())[0]\n", + " reference_image = Image.open(ref_path).convert(\"RGB\")\n", + "else:\n", + " reference_image = Image.new(\"RGB\", (target_width, target_height), \"#181818\")\n", + "\n", + "# ================= INFERENCE =================\n", + "print(\"πŸš€ Running inference + encryption...\")\n", + "\n", + "for i, img_path in enumerate(image_files):\n", + " gc.collect()\n", + " torch.cuda.empty_cache()\n", + "\n", + " filename = os.path.basename(img_path)\n", + " img = Image.open(img_path).convert(\"RGB\")\n", + "\n", + " # resize\n", + " if max(img.width, img.height) > max_image_dimension:\n", + " aspect = img.width / img.height\n", + " if img.width > img.height:\n", + " img = img.resize((max_image_dimension, int(max_image_dimension/aspect)), Image.LANCZOS)\n", + " else:\n", + " img = img.resize((int(max_image_dimension*aspect), max_image_dimension), Image.LANCZOS)\n", + "\n", + " result = pipe(\n", + " prompt=edit_prompt,\n", + " image=[img, reference_image],\n", + " height=target_height,\n", + " width=target_width,\n", + " guidance_scale=1.0,\n", + " num_inference_steps=4,\n", + " generator=torch.Generator(\"cuda\").manual_seed(42),\n", + " output_type=\"pil\",\n", + " ).images[0]\n", + "\n", + " # ===== ENCRYPT SAVE =====\n", + " img_bytes = pil_to_bytes(result)\n", + " encrypted_data = encrypt_bytes(img_bytes)\n", + "\n", + " out_name = f\"{os.path.splitext(filename)[0]}_encrypted.bin\"\n", + " out_path = os.path.join(output_folder, out_name)\n", + "\n", + " with open(out_path, \"wb\") as f:\n", + " f.write(encrypted_data)\n", + "\n", + " print(f\"[{i+1}/{len(image_files)}] πŸ” saved β†’ {out_path}\")\n", + "\n", + "# ================= ZIP =================\n", + "timestamp = datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")\n", + "final_zip = f\"/content/drive/MyDrive/klein_encrypted_{timestamp}.zip\"\n", + "\n", + "shutil.make_archive(final_zip.replace('.zip',''), 'zip', output_folder)\n", + "\n", + "print(f\"\\nπŸ“¦ Final encrypted zip β†’ {final_zip}\")\n", + "print(\"βœ… DONE\")" + ], + "metadata": { + "cellView": "form", + "id": "x_8QixuPcNhL" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# Clean unassigned junk files from VRAM , run this if interrupting the cell script\n", + "import torch , gc\n", + "torch.cuda.empty_cache()\n", + "gc.collect()" + ], + "metadata": { + "id": "e46WUV7jMInu" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# πŸ”Œ Auto Disconnect from Drive\n", + "\n", + "Results from earlier cell have been saved to your drive as\n", + "'content/drive/MyDrive/klein_processed_(date_number).zip'\n", + "\n", + "You can disconnect from the session , and reconnect to new runtime to prevent conflict in installed libraries. you can run this code on CPU" + ], + "metadata": { + "id": "7eeX3_qpYpwl" + } + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "FQF71-mvmlc1", + "cellView": "form" + }, + "outputs": [], + "source": [ + "# ================================================\n", + "#@title πŸ”Œ Auto Disconnect Colab Session\n", + "# ================================================\n", + "\n", + "enable = False #@param {type:'boolean'}\n", + "if enable:\n", + " print(\"πŸ”Œ Disconnecting Colab session in 3 seconds...\")\n", + " import time\n", + " time.sleep(3)\n", + "\n", + " from google.colab import runtime\n", + " runtime.unassign()\n", + "\n", + " print(\"Session disconnected.\")" + ] + }, + { + "cell_type": "markdown", + "source": [ + "# πŸ”‘ Decrypt (wip)" + ], + "metadata": { + "id": "pke7YfSHd4u6" + } + }, + { + "cell_type": "code", + "source": [ + "# =============================================================================\n", + "# πŸ”‘ Session C: Decrypt most recent encrypted ZIP from Drive (FULLY COMPATIBLE)\n", + "# =============================================================================\n", + "\n", + "from google.colab import drive, files\n", + "import os\n", + "import zipfile\n", + "import io\n", + "import hashlib\n", + "from PIL import Image\n", + "\n", + "!pip install -q pynacl\n", + "from nacl.secret import SecretBox\n", + "\n", + "# =============================================================================\n", + "# 1. Mount Drive\n", + "# =============================================================================\n", + "drive.mount('/content/drive')\n", + "\n", + "# =============================================================================\n", + "# 2. Config\n", + "# =============================================================================\n", + "decryption_password = \"banana\" #@param{type:'string'}\n", + "output_zip_name = \"decrypted_results.zip\" #@param {type:\"string\"}\n", + "image_format = \"JPG\" #@param [\"PNG\", \"JPG\"]\n", + "jpeg_quality = 95 #@param {type:\"slider\", min:1, max:100, step:1}\n", + "\n", + "output_base_folder = \"/content/zip_outputs\"\n", + "os.makedirs(output_base_folder, exist_ok=True)\n", + "\n", + "# =============================================================================\n", + "# 3. Key setup\n", + "# =============================================================================\n", + "def derive_key(password):\n", + " return hashlib.sha256(password.encode()).digest()\n", + "\n", + "box = SecretBox(derive_key(decryption_password))\n", + "\n", + "def decrypt_bytes(enc):\n", + " nonce = enc[:24]\n", + " ciphertext = enc[24:]\n", + " return box.decrypt(ciphertext, nonce)\n", + "\n", + "# =============================================================================\n", + "# 4. Find MOST RECENT matching ZIP\n", + "# =============================================================================\n", + "drive_base_folder = \"/content/drive/MyDrive\"\n", + "search_folders = [\n", + " drive_base_folder,\n", + " os.path.join(drive_base_folder, \"Saved from Chrome\")\n", + "]\n", + "\n", + "print(\"πŸ” Searching for encrypted ZIPs...\")\n", + "\n", + "matching_zips = []\n", + "\n", + "for folder in search_folders:\n", + " if not os.path.exists(folder):\n", + " continue\n", + "\n", + " for f in os.listdir(folder):\n", + " f_lower = f.lower()\n", + "\n", + " is_zip = f_lower.endswith(\".zip\")\n", + "\n", + " # ===== SUPPORT OLD + NEW NAMING =====\n", + " contains_old = \"klein_encrypted_outputs\" in f_lower\n", + " contains_new = \"klein_encrypted_\" in f_lower\n", + " contains_checkpoint = \"checkpoint_gpu\" in f_lower\n", + "\n", + " if is_zip and (contains_old or contains_new or contains_checkpoint):\n", + " full_path = os.path.join(folder, f)\n", + " matching_zips.append(full_path)\n", + " print(f\"βœ… Found: {f}\")\n", + "\n", + "if not matching_zips:\n", + " raise FileNotFoundError(\"❌ No matching encrypted ZIP found.\")\n", + "\n", + "most_recent_zip = max(matching_zips, key=os.path.getmtime)\n", + "\n", + "print(f\"\\nπŸ“¦ Using most recent: {os.path.basename(most_recent_zip)}\")\n", + "\n", + "# =============================================================================\n", + "# 5. Decrypt ZIP\n", + "# =============================================================================\n", + "def decrypt_zip(zip_path):\n", + " images = []\n", + "\n", + " with zipfile.ZipFile(zip_path, \"r\") as z:\n", + " names = z.namelist()\n", + "\n", + " # ===== SUPPORT .enc + .bin =====\n", + " enc_names = [\n", + " n for n in names\n", + " if n.endswith(\".enc\") or n.endswith(\".bin\")\n", + " ]\n", + "\n", + " print(f\"πŸ”“ Found {len(enc_names)} encrypted files\")\n", + "\n", + " for name in enc_names:\n", + " enc_data = z.read(name)\n", + "\n", + " try:\n", + " dec = decrypt_bytes(enc_data)\n", + " img = Image.open(io.BytesIO(dec)).convert(\"RGB\")\n", + " images.append(img)\n", + " except Exception as e:\n", + " print(f\"⚠️ Failed to decrypt: {name} ({e})\")\n", + "\n", + " return images\n", + "\n", + "all_images = decrypt_zip(most_recent_zip)\n", + "\n", + "if len(all_images) == 0:\n", + " raise RuntimeError(\"❌ No images decrypted. Likely wrong password or format mismatch.\")\n", + "\n", + "# =============================================================================\n", + "# 6. Build output ZIP\n", + "# =============================================================================\n", + "final_zip = os.path.join(output_base_folder, output_zip_name)\n", + "\n", + "print(f\"\\nπŸ“¦ Creating output ZIP with {len(all_images)} images...\")\n", + "\n", + "with zipfile.ZipFile(final_zip, \"w\", compression=zipfile.ZIP_DEFLATED) as zf:\n", + " ext = \"png\" if image_format == \"PNG\" else \"jpg\"\n", + "\n", + " for i, img in enumerate(all_images):\n", + " buf = io.BytesIO()\n", + "\n", + " if image_format == \"JPG\":\n", + " img.save(buf, format=\"JPEG\", quality=jpeg_quality, optimize=True)\n", + " else:\n", + " img.save(buf, format=\"PNG\")\n", + "\n", + " zf.writestr(f\"{i:05d}.{ext}\", buf.getvalue())\n", + "\n", + "# =============================================================================\n", + "# 7. Download\n", + "# =============================================================================\n", + "files.download(final_zip)\n", + "\n", + "print(\"⬇️ Download started\")\n", + "print(\"βœ… Decryption complete\")" + ], + "metadata": { + "id": "YMKzCydjd6mo", + "cellView": "form" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# Select Klein processed file to use next" + ], + "metadata": { + "id": "s7R3l3-pY5W7" + } + }, + { + "cell_type": "code", + "source": [ + "from google.colab import drive\n", + "drive.mount('/content/drive')" + ], + "metadata": { + "id": "ijzwEoboHVPR" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "OdcEXFs4oBt_", + "cellView": "form" + }, + "outputs": [], + "source": [ + "import os\n", + "\n", + "klein_edited_zip_path = '/content/drive/MyDrive/klein_processed.zip' #@param {type:'string'}\n", + "zip_path = klein_edited_zip_path\n", + "\n", + "if not os.path.exists(zip_path):\n", + " raise FileNotFoundError(f\"❌ Klein edited zip file not found:\\n{zip_path}\\n\\nPlease ensure the path is correct and the file exists in your Drive.\")" + ] + }, + { + "cell_type": "markdown", + "source": [ + "# βš™οΈ Create 1024x1024 frames from selected klein edited set" + ], + "metadata": { + "id": "4PjK9a8Sni3A" + } + }, + { + "cell_type": "code", + "source": [ + "#@title πŸ–ΌοΈ **Image Background Processor (v1)**\n", + "#@markdown ---\n", + "#@markdown ## Enable Processor V1\n", + "enable_processor_v1 = False #@param {type:\"boolean\"}\n", + "\n", + "#@title πŸ–ΌοΈ **Image Background Processor**\n", + "#(v2 - Solid #181818 Flood-Fill + Auto-Clear)\n", + "#**Crop left/right empty space + Convert *any* gray background to exact #181818**\n", + "#@markdown ---\n", + "#**New**: Automatically clears all previous processed images on re-run\n", + "#(no more mixing old files when you run again)\n", + "\n", + "#Run this cell (Shift + Enter)\n", + "#Fill the form below\n", + "#Click **Run**\n", + "\n", + "# ==================== FORM PARAMETERS ====================\n", + "\n", + "#input_zip_path = \"/content/drive/MyDrive/klein_processed.zip\" #@param {type:\"string\", placeholder:\"Paste full path to your ZIP file here\"}\n", + "input_zip_path = zip_path\n", + "\n", + "tolerance_crop = 50 #@param {type:\"slider\", min:0, max:100, step:1, title:\"🟦 Crop Tolerance (higher = more aggressive cropping)\"}\n", + "\n", + "bg_replace_threshold = 20 #@param {type:\"slider\", min:10, max:100, step:1}\n", + "\n", + "force_remount = False #@param {type:\"boolean\", title:\"πŸ”„ Force remount Drive (recommended)\"}\n", + "\n", + "#@markdown ---\n", + "\n", + "\n", + "if enable_processor_v1:\n", + " from google.colab import drive\n", + " import zipfile\n", + " import os\n", + " import shutil # ← NEW for clearing folders\n", + " from PIL import Image\n", + " from collections import deque\n", + "\n", + " # ========================= CONFIG =========================\n", + " TARGET_GRAY = (24, 24, 24) # Exact #181818 - do not change\n", + " # =======================================================\n", + "\n", + " print(\"πŸš€ Starting image processor (Solid Background v2 + Auto-Clear)...\")\n", + "\n", + " # 1. Mount Google Drive\n", + " drive.mount('/content/drive', force_remount=force_remount)\n", + "\n", + " # 2. Validate ZIP path\n", + " if not input_zip_path or not os.path.exists(input_zip_path):\n", + " raise FileNotFoundError(f\"❌ ZIP file not found:\\n{input_zip_path}\\n\\nPlease paste the correct full path (e.g. /content/drive/MyDrive/my_photos.zip)\")\n", + "\n", + " print(f\"βœ… ZIP found: {input_zip_path}\")\n", + "\n", + " # 3. Define working folders\n", + " extract_dir = '/content/extracted_images'\n", + " processed_dir = '/content/processed_images'\n", + "\n", + " # === NEW: Clear previous processed & extracted images on every run ===\n", + " for directory in [extract_dir, processed_dir]:\n", + " if os.path.exists(directory):\n", + " shutil.rmtree(directory)\n", + " print(f\"🧹 Cleared old folder: {directory}\")\n", + " os.makedirs(extract_dir, exist_ok=True)\n", + " os.makedirs(processed_dir, exist_ok=True)\n", + " print(\"βœ… Fresh folders ready\")\n", + "\n", + " # 4. Unzip\n", + " print(\"πŸ“¦ Unzipping...\")\n", + " with zipfile.ZipFile(input_zip_path, 'r') as zip_ref:\n", + " zip_ref.extractall(extract_dir)\n", + " print(f\"βœ… Unzipped to {extract_dir}\")\n", + "\n", + " # ==================== HELPER 1: Crop only left & right ====================\n", + " def crop_left_right(img):\n", + " if img.mode != 'RGB':\n", + " img = img.convert('RGB')\n", + "\n", + " width, height = img.size\n", + " bg_color = img.getpixel((0, 0))\n", + "\n", + " left = width\n", + " right = 0\n", + "\n", + " for x in range(width):\n", + " column_is_empty = True\n", + " for y in range(height):\n", + " px = img.getpixel((x, y))\n", + " if any(abs(a - b) > tolerance_crop for a, b in zip(px, bg_color)):\n", + " column_is_empty = False\n", + " break\n", + " if not column_is_empty:\n", + " left = min(left, x)\n", + " right = max(right, x)\n", + "\n", + " if left >= right:\n", + " return img\n", + "\n", + " return img.crop((left, 0, right + 1, height))\n", + "\n", + " # ==================== HELPER 2: FLOOD-FILL BACKGROUND FROM EDGES ====================\n", + " def adjust_background(img, original_bg_color):\n", + " if img.mode != 'RGB':\n", + " img = img.convert('RGB')\n", + "\n", + " width, height = img.size\n", + " pixels = img.load()\n", + " threshold = bg_replace_threshold\n", + "\n", + " visited = set()\n", + " queue = deque()\n", + " directions = [(dx, dy) for dx in [-1, 0, 1] for dy in [-1, 0, 1] if not (dx == 0 and dy == 0)]\n", + "\n", + " # Seed from borders\n", + " for x in range(width):\n", + " for y in (0, height - 1):\n", + " if (x, y) not in visited:\n", + " px = pixels[x, y]\n", + " dist = ((px[0] - original_bg_color[0])**2 + (px[1] - original_bg_color[1])**2 + (px[2] - original_bg_color[2])**2) ** 0.5\n", + " if dist <= threshold:\n", + " queue.append((x, y))\n", + " visited.add((x, y))\n", + " pixels[x, y] = TARGET_GRAY\n", + "\n", + " for y in range(height):\n", + " for x in (0, width - 1):\n", + " if (x, y) not in visited:\n", + " px = pixels[x, y]\n", + " dist = ((px[0] - original_bg_color[0])**2 + (px[1] - original_bg_color[1])**2 + (px[2] - original_bg_color[2])**2) ** 0.5\n", + " if dist <= threshold:\n", + " queue.append((x, y))\n", + " visited.add((x, y))\n", + " pixels[x, y] = TARGET_GRAY\n", + "\n", + " # Flood fill\n", + " while queue:\n", + " x, y = queue.popleft()\n", + " for dx, dy in directions:\n", + " nx, ny = x + dx, y + dy\n", + " if 0 <= nx < width and 0 <= ny < height and (nx, ny) not in visited:\n", + " px = pixels[nx, ny]\n", + " dist = ((px[0] - original_bg_color[0])**2 + (px[1] - original_bg_color[1])**2 + (px[2] - original_bg_color[2])**2) ** 0.5\n", + " if dist <= threshold:\n", + " visited.add((nx, ny))\n", + " pixels[nx, ny] = TARGET_GRAY\n", + " queue.append((nx, ny))\n", + "\n", + " return img\n", + "\n", + " # 5. Process every image\n", + " print(\"πŸ–ΌοΈ Processing images...\")\n", + " image_extensions = ('.png', '.jpg', '.jpeg', '.bmp', '.tiff', '.webp')\n", + "\n", + " processed_count = 0\n", + " for filename in os.listdir(extract_dir):\n", + " if filename.lower().endswith(image_extensions):\n", + " img_path = os.path.join(extract_dir, filename)\n", + " try:\n", + " with Image.open(img_path) as original_img:\n", + " cropped = crop_left_right(original_img)\n", + " orig_bg = original_img.getpixel((0, 0))\n", + " processed = adjust_background(cropped, orig_bg)\n", + "\n", + " out_path = os.path.join(processed_dir, filename)\n", + " processed.save(out_path, quality=95 if filename.lower().endswith(('.jpg', '.jpeg')) else None)\n", + "\n", + " processed_count += 1\n", + " print(f\" βœ… {filename}\")\n", + " except Exception as e:\n", + " print(f\" ❌ Skipped {filename}: {e}\")\n", + "\n", + " print(f\"\\nπŸŽ‰ Processed {processed_count} images!\")\n", + "\n", + " # 6. Create final ZIP in Drive\n", + " output_zip_name = \"PROCESSED_\" + os.path.basename(zip_path)\n", + " output_zip_path = os.path.join(os.path.dirname(zip_path), output_zip_name)\n", + " zip_path = output_zip_path\n", + "\n", + " print(f\"πŸ“¦ Creating final ZIP: {output_zip_name}\")\n", + " with zipfile.ZipFile(output_zip_path, 'w', zipfile.ZIP_DEFLATED) as zip_out:\n", + " for root, _, files in os.walk(processed_dir):\n", + " for file in files:\n", + " file_path = os.path.join(root, file)\n", + " arcname = os.path.relpath(file_path, processed_dir)\n", + " zip_out.write(file_path, arcname)\n", + "\n", + " print(\"\\nβœ… ALL DONE! Solid #181818 background achieved.\")\n", + " print(f\"πŸ“ Saved to your Drive at:\\n {output_zip_path}\")\n" + ], + "metadata": { + "id": "HN4kta-OpZ4W", + "cellView": "form" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "#@title **πŸ–ΌοΈ Image Background Processor V2 (WIP)**\n", + "#@markdown ---\n", + "#@markdown ## Enable Processor V2\n", + "enable_processor_v2 = True #@param {type:\"boolean\"}\n", + "\n", + "#@title **πŸ–ΌοΈ Image Background Processor V2 (WIP)**\n", + "#(v2.7 - **Inverse speck removal** + Border-protected forward speck + % Margin + Solid #181818)\n", + "\n", + "#**Crop left/right empty space + Convert *any* gray background to exact #181818**\n", + "#**New in v2.7**:\n", + "# β€’ **Inverse speck removal**: finds tiny foreground (subject-colored) specks/islands inside the background and replaces them with solid #181818\n", + "# β€’ Forward speck removal (previous) still protects any #181818 connected to the outer image edge\n", + "# β€’ Anti-aliasing is guaranteed to be the **very last step** (after both forward + inverse speck removal)\n", + "# β€’ All previous features (4-corner BG, % margin, checkboxes, distance-based enclosed speck removal) unchanged\n", + "\n", + "# ==================== FORM PARAMETERS ====================\n", + "\n", + "input_zip_path = zip_path\n", + "\n", + "tolerance_crop = 60 #@param {type:\"slider\", min:0, max:100, step:1, title:\"πŸ”΅ Crop Tolerance (higher = more aggressive cropping)\"}\n", + "\n", + "bg_replace_threshold = 10 #@param {type:\"slider\", min:10, max:100, step:1, title:\"🎨 Legacy absolute threshold (kept for compatibility)\"}\n", + "\n", + "# ── % Margin for BG color estimation ──\n", + "bg_margin_percent = 6 #@param {type:\"slider\", min:0, max:50, step:1, title:\"% Margin for BG color estimation (wider = more tolerant to inner-loop gray variations)\"}\n", + "\n", + "# ── Feature Checkboxes ──\n", + "enable_robust_bg_detection = True #@param {type:\"boolean\", title:\"βœ… Use 4-corner robust BG color (best for inner loops)\"}\n", + "enable_floodfill_background_adjustment = True #@param {type:\"boolean\", title:\"βœ… Enable solid #181818 background replacement\"}\n", + "enable_small_speck_removal = True #@param {type:\"boolean\"}\n", + "#title:\"βœ… Forward speck removal: remove tiny #181818 specks on subject\"}\n", + "enable_inverse_speck_removal = True #@param {type:\"boolean\"}\n", + "#title:\"βœ… Inverse speck removal: fill tiny subject specks inside background with #181818\"}\n", + "enable_anti_aliasing = True #@param {type:\"boolean\", title:\"βœ… Smooth edges (Gaussian anti-aliasing)\"}\n", + "\n", + "anti_aliasing_strength = 6 #@param {type:\"slider\", min:1, max:40, step:1, title:\" ↳ Anti-aliasing Strength (pixels to blend)\"}\n", + "\n", + "# ── Forward speck removal (enclosed only) ──\n", + "min_floodfill_steps = 8 #@param {type:\"slider\", min:1, max:20, step:1, title:\" ↳ Min floodfill steps to foreground (N) for ENCLOSED BG only (outer-edge-connected BG always protected)\"}\n", + "\n", + "# ── Inverse speck removal ──\n", + "max_inverse_speck_size = 10 #@param {type:\"slider\", min:1, max:100, step:1, title:\" ↳ Max size of foreground specks to fill with #181818\"}\n", + "\n", + "force_remount = False #@param {type:\"boolean\", title:\"πŸ”„ Force remount Drive\"}\n", + "\n", + "#@markdown ---\n", + "\n", + "\n", + "if enable_processor_v2:\n", + " from google.colab import drive\n", + " import zipfile\n", + " import os\n", + " import shutil\n", + " from PIL import Image, ImageFilter\n", + " from collections import deque\n", + "\n", + " # ========================= CONFIG =========================\n", + " TARGET_GRAY = (24, 24, 24) # Exact #181818\n", + " # =======================================================\n", + "\n", + " print(\"πŸš€ Starting Image Background Processor v2.7 (Forward + Inverse speck removal)...\")\n", + "\n", + " # 1. Mount Google Drive\n", + " drive.mount('/content/drive', force_remount=force_remount)\n", + "\n", + " # 2. Validate ZIP path\n", + " if not input_zip_path or not os.path.exists(input_zip_path):\n", + " raise FileNotFoundError(f\"❌ ZIP file not found:\\n{input_zip_path}\\n\\nPlease paste the correct full path\")\n", + "\n", + " print(f\"βœ… ZIP found: {input_zip_path}\")\n", + "\n", + " # 3. Define working folders\n", + " extract_dir = '/content/extracted_images'\n", + " processed_dir = '/content/processed_images'\n", + "\n", + " # Clear previous runs\n", + " for directory in [extract_dir, processed_dir]:\n", + " if os.path.exists(directory):\n", + " shutil.rmtree(directory)\n", + " print(f\"οΉ… Cleared old folder: {directory}\")\n", + " os.makedirs(extract_dir, exist_ok=True)\n", + " os.makedirs(processed_dir, exist_ok=True)\n", + " print(\"βœ… Fresh folders ready\")\n", + "\n", + " # 4. Unzip\n", + " print(\"πŸš€ Unzipping...\")\n", + " with zipfile.ZipFile(input_zip_path, 'r') as zip_ref:\n", + " zip_ref.extractall(extract_dir)\n", + " print(f\"βœ… Unzipped to {extract_dir}\")\n", + "\n", + " # ==================== HELPER 1: Crop only left & right ====================\n", + " def crop_left_right(img):\n", + " if img.mode != 'RGB':\n", + " img = img.convert('RGB')\n", + " width, height = img.size\n", + " bg_color = img.getpixel((0, 0))\n", + " left = width\n", + " right = 0\n", + " for x in range(width):\n", + " column_is_empty = True\n", + " for y in range(height):\n", + " px = img.getpixel((x, y))\n", + " if any(abs(a - b) > tolerance_crop for a, b in zip(px, bg_color)):\n", + " column_is_empty = False\n", + " break\n", + " if not column_is_empty:\n", + " left = min(left, x)\n", + " right = max(right, x)\n", + " if left >= right:\n", + " return img\n", + " return img.crop((left, 0, right + 1, height))\n", + "\n", + " # ==================== HELPER 2: FULL BACKGROUND PROCESSOR (v2.7) ====================\n", + " def adjust_background(img, original_bg_color,\n", + " enable_floodfill_background_adjustment,\n", + " enable_small_speck_removal,\n", + " enable_inverse_speck_removal,\n", + " enable_anti_aliasing,\n", + " anti_aliasing_strength,\n", + " min_floodfill_steps,\n", + " max_inverse_speck_size,\n", + " bg_margin_percent):\n", + " if img.mode != 'RGB':\n", + " img = img.convert('RGB')\n", + "\n", + " width, height = img.size\n", + " pixels_access = img.load()\n", + " target_gray = TARGET_GRAY\n", + " directions = [(dx, dy) for dx in [-1, 0, 1] for dy in [-1, 0, 1] if not (dx == 0 and dy == 0)]\n", + "\n", + " # 1. Identify foreground using % margin\n", + " per_channel_margin = int(255 * (bg_margin_percent / 100.0))\n", + " is_foreground = [[False for _ in range(height)] for _ in range(width)]\n", + " for y in range(height):\n", + " for x in range(width):\n", + " px = pixels_access[(x, y)]\n", + " is_bg = all(abs(px[i] - original_bg_color[i]) <= per_channel_margin for i in range(3))\n", + " if not is_bg:\n", + " is_foreground[x][y] = True\n", + "\n", + " # 2. Base image: solid #181818 + foreground\n", + " base_processed_img = Image.new(\"RGB\", (width, height), target_gray)\n", + " base_processed_pixels = base_processed_img.load()\n", + " for y in range(height):\n", + " for x in range(width):\n", + " if is_foreground[x][y]:\n", + " base_processed_pixels[(x, y)] = pixels_access[(x, y)]\n", + "\n", + " # 3. Forward speck removal (border-protected, enclosed only)\n", + " if enable_floodfill_background_adjustment and enable_small_speck_removal:\n", + " print(\" πŸ” Running forward speck removal (border-protected)...\")\n", + " refined_img = base_processed_img.copy()\n", + " refined_pixels = refined_img.load()\n", + "\n", + " # Mark border-connected #181818\n", + " connected_to_border = [[False] * height for _ in range(width)]\n", + " queue = deque()\n", + " for x in range(width):\n", + " for y_border in [0, height-1]:\n", + " if refined_pixels[(x, y_border)] == target_gray and not connected_to_border[x][y_border]:\n", + " connected_to_border[x][y_border] = True\n", + " queue.append((x, y_border))\n", + " for y in range(height):\n", + " for x_border in [0, width-1]:\n", + " if refined_pixels[(x_border, y)] == target_gray and not connected_to_border[x_border][y]:\n", + " connected_to_border[x_border][y] = True\n", + " queue.append((x_border, y))\n", + " while queue:\n", + " cx, cy = queue.popleft()\n", + " for dx, dy in directions:\n", + " nx, ny = cx + dx, cy + dy\n", + " if 0 <= nx < width and 0 <= ny < height and not connected_to_border[nx][ny] and refined_pixels[(nx, ny)] == target_gray:\n", + " connected_to_border[nx][ny] = True\n", + " queue.append((nx, ny))\n", + "\n", + " # Distance to foreground (for enclosed BG only)\n", + " distance = [[-1] * height for _ in range(width)]\n", + " queue = deque()\n", + " for y in range(height):\n", + " for x in range(width):\n", + " if is_foreground[x][y]:\n", + " for dx, dy in directions:\n", + " nx, ny = x + dx, y + dy\n", + " if 0 <= nx < width and 0 <= ny < height and not is_foreground[nx][ny] and distance[nx][ny] == -1:\n", + " distance[nx][ny] = 1\n", + " queue.append((nx, ny))\n", + " break\n", + " while queue:\n", + " cx, cy = queue.popleft()\n", + " for dx, dy in directions:\n", + " nx, ny = cx + dx, cy + dy\n", + " if 0 <= nx < width and 0 <= ny < height and not is_foreground[nx][ny] and distance[nx][ny] == -1:\n", + " distance[nx][ny] = distance[cx][cy] + 1\n", + " queue.append((nx, ny))\n", + "\n", + " # Revert only enclosed + too-close BG pixels\n", + " for y in range(height):\n", + " for x in range(width):\n", + " if refined_pixels[(x, y)] == target_gray:\n", + " if not connected_to_border[x][y] and (distance[x][y] == -1 or distance[x][y] < min_floodfill_steps):\n", + " refined_pixels[(x, y)] = pixels_access[(x, y)]\n", + "\n", + " base_processed_img = refined_img\n", + " base_processed_pixels = base_processed_img.load()\n", + "\n", + " # 4. INVERSE speck removal (tiny foreground specks inside background β†’ #181818)\n", + " if enable_floodfill_background_adjustment and enable_inverse_speck_removal:\n", + " print(\" πŸ” Running inverse speck removal (small FG specks β†’ #181818)...\")\n", + " refined_img = base_processed_img.copy()\n", + " refined_pixels = refined_img.load()\n", + " visited = [[False] * height for _ in range(width)]\n", + "\n", + " for y in range(height):\n", + " for x in range(width):\n", + " if refined_pixels[(x, y)] != target_gray and not visited[x][y]:\n", + " component = []\n", + " queue = deque([(x, y)])\n", + " visited[x][y] = True\n", + " while queue:\n", + " cx, cy = queue.popleft()\n", + " component.append((cx, cy))\n", + " for dx, dy in directions:\n", + " nx, ny = cx + dx, cy + dy\n", + " if 0 <= nx < width and 0 <= ny < height and not visited[nx][ny] and refined_pixels[(nx, ny)] != target_gray:\n", + " visited[nx][ny] = True\n", + " queue.append((nx, ny))\n", + " # Fill small foreground specks with solid #181818\n", + " if len(component) < max_inverse_speck_size:\n", + " for px, py in component:\n", + " refined_pixels[(px, py)] = target_gray\n", + "\n", + " base_processed_img = refined_img\n", + " base_processed_pixels = base_processed_img.load()\n", + "\n", + " # 5. Anti-aliasing – ALWAYS LAST (as requested)\n", + " if not enable_anti_aliasing:\n", + " return base_processed_img\n", + "\n", + " mask = Image.new(\"L\", (width, height), 0)\n", + " mask_pixels = mask.load()\n", + " for y in range(height):\n", + " for x in range(width):\n", + " if base_processed_pixels[(x, y)] != target_gray:\n", + " mask_pixels[(x, y)] = 255\n", + "\n", + " blur_radius = anti_aliasing_strength / 2.0\n", + " blurred_mask = mask.filter(ImageFilter.GaussianBlur(radius=blur_radius))\n", + "\n", + " solid_bg = Image.new(\"RGB\", (width, height), target_gray)\n", + " final_img_with_aa = Image.composite(base_processed_img, solid_bg, blurred_mask)\n", + "\n", + " return final_img_with_aa\n", + "\n", + " # ==================== MAIN PROCESSING LOOP ====================\n", + " print(\"πŸš€ Processing images...\")\n", + " image_extensions = ('.png', '.jpg', '.jpeg', '.bmp', '.tiff', '.webp')\n", + "\n", + " processed_count = 0\n", + " for filename in os.listdir(extract_dir):\n", + " if filename.lower().endswith(image_extensions):\n", + " img_path = os.path.join(extract_dir, filename)\n", + " try:\n", + " with Image.open(img_path) as original_img:\n", + " # === ROBUST BACKGROUND COLOR DETECTION ===\n", + " cropped = crop_left_right(original_img)\n", + " if cropped.mode != 'RGB':\n", + " cropped = cropped.convert('RGB')\n", + "\n", + " if enable_robust_bg_detection:\n", + " w, h = cropped.size\n", + " samples = [\n", + " cropped.getpixel((0, 0)),\n", + " cropped.getpixel((w-1, 0)),\n", + " cropped.getpixel((0, h-1)),\n", + " cropped.getpixel((w-1, h-1))\n", + " ]\n", + " orig_bg = tuple(sum(c) // len(samples) for c in zip(*samples))\n", + " print(f\" πŸ“ Using robust 4-corner BG color for {filename}\")\n", + " else:\n", + " orig_bg = cropped.getpixel((0, 0))\n", + "\n", + " # === PROCESS IMAGE ===\n", + " if enable_floodfill_background_adjustment:\n", + " processed = adjust_background(\n", + " cropped,\n", + " orig_bg,\n", + " enable_floodfill_background_adjustment,\n", + " enable_small_speck_removal,\n", + " enable_inverse_speck_removal,\n", + " enable_anti_aliasing,\n", + " anti_aliasing_strength,\n", + " min_floodfill_steps,\n", + " max_inverse_speck_size,\n", + " bg_margin_percent\n", + " )\n", + " else:\n", + " processed = cropped\n", + "\n", + " out_path = os.path.join(processed_dir, filename)\n", + " processed.save(out_path, quality=95 if filename.lower().endswith(('.jpg', '.jpeg')) else None)\n", + "\n", + " processed_count += 1\n", + " print(f\" βœ… {filename}\")\n", + "\n", + " except Exception as e:\n", + " print(f\" ❌ Skipped {filename}: {e}\")\n", + "\n", + " print(f\"\\nπŸŽ‰ Processed {processed_count} images!\")\n", + "\n", + " # 6. Create final ZIP\n", + " output_zip_name = \"PROCESSED_\" + os.path.basename(input_zip_path)\n", + " output_zip_path = os.path.join(os.path.dirname(input_zip_path), output_zip_name)\n", + "\n", + " print(f\"πŸš€ Creating final ZIP: {output_zip_name}\")\n", + " with zipfile.ZipFile(output_zip_path, 'w', zipfile.ZIP_DEFLATED) as zip_out:\n", + " for root, _, files in os.walk(processed_dir):\n", + " for file in files:\n", + " file_path = os.path.join(root, file)\n", + " arcname = os.path.relpath(file_path, processed_dir)\n", + " zip_out.write(file_path, arcname)\n", + "\n", + " print(\"\\nβœ… ALL DONE! Solid #181818 everywhere (forward + inverse specks cleaned) + smooth AA last\")\n", + " print(f\"πŸ“ Saved to your Drive at:\\n {output_zip_path}\")\n" + ], + "metadata": { + "cellView": "form", + "id": "tFGWg7jNv4mo" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "# βš™οΈ Create composites" + ], + "metadata": { + "id": "kVAe29swHo4I" + } + }, + { + "cell_type": "code", + "source": [ + "#@markdown Set zip file input path for making composites\n", + "input_zip_path = \"/content/drive/MyDrive/PROCESSED_klein_processed.zip\" #@param {type:'string'}\n", + "zip_file_path = input_zip_path" + ], + "metadata": { + "id": "IXQKiBVrNPcE" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "93JpoQJ77NGu", + "cellView": "form" + }, + "outputs": [], + "source": [ + "# ────────────────────────────────────────────────\n", + "# 🎨 CLEAN ROW β†’ PURE 1024x1024 FRAMES (NO DISTORTION)\n", + "# ────────────────────────────────────────────────\n", + "\n", + "#@markdown ## βš™οΈ Main Settings\n", + "num_frames = 100 #@param {type:\"slider\", min:10, max:2000, step:10}\n", + "overlap_percent = 0 #@param {type:\"slider\", min:0, max:50, step:1}\n", + "min_step_ratio = 0.8 #@param {type:\"slider\", min:0.5, max:1.0, step:0.05}\n", + "max_step_ratio = 1.0 #@param {type:\"slider\", min:0.8, max:1.5, step:0.05}\n", + "\n", + "#@markdown ## 🧱 Border\n", + "border_width = 8 #@param {type:\"slider\", min:0, max:100}\n", + "\n", + "#@markdown ## πŸ’Ύ Input / Output\n", + "save_to_google_drive = True #@param {type:\"boolean\"}\n", + "drive_folder_name = \"vertical_slices_output\" #@param {type:\"string\"}\n", + "# ────────────────────────────────────────────────\n", + "\n", + "FRAME_SIZE = 1024\n", + "INNER_SIZE = FRAME_SIZE - 2 * border_width\n", + "BORDER_COLOR = (24, 24, 24)\n", + "\n", + "import os, random, zipfile\n", + "import numpy as np\n", + "from PIL import Image\n", + "from google.colab import drive\n", + "\n", + "# ────────────────────────────────────────────────\n", + "# Mount Drive\n", + "# ────────────────────────────────────────────────\n", + "\n", + "drive_mounted = False\n", + "if save_to_google_drive:\n", + " try:\n", + " drive.mount('/content/drive', force_remount=False)\n", + " drive_mounted = True\n", + " drive_output_dir = os.path.join(\"/content/drive/MyDrive\", drive_folder_name)\n", + " os.makedirs(drive_output_dir, exist_ok=True)\n", + " print(\"Drive mounted\")\n", + " except:\n", + " save_to_google_drive = False\n", + "\n", + "# ────────────────────────────────────────────────\n", + "# Extract ZIP\n", + "# ────────────────────────────────────────────────\n", + "\n", + "extract_root = \"/content/extracted_images\"\n", + "output_dir = \"/content/frames\"\n", + "\n", + "os.makedirs(extract_root, exist_ok=True)\n", + "os.makedirs(output_dir, exist_ok=True)\n", + "\n", + "with zipfile.ZipFile(zip_file_path, 'r') as zf:\n", + " zf.extractall(extract_root)\n", + "\n", + "# ────────────────────────────────────────────────\n", + "# Load images\n", + "# ────────────────────────────────────────────────\n", + "\n", + "valid_exts = ('.jpg','.jpeg','.png','.webp')\n", + "all_sources = []\n", + "\n", + "for root, _, files in os.walk(extract_root):\n", + " for f in files:\n", + " if f.lower().endswith(valid_exts):\n", + " all_sources.append(os.path.join(root, f))\n", + "\n", + "print(\"Images found:\", len(all_sources))\n", + "\n", + "# ────────────────────────────────────────────────\n", + "# Build row UNTIL enough width\n", + "# ────────────────────────────────────────────────\n", + "\n", + "def build_row_until_width(all_sources, target_h, overlap_ratio, required_width):\n", + " canvas = Image.new(\"RGB\", (required_width, target_h))\n", + " x = 0\n", + "\n", + " while x < required_width:\n", + " src = random.choice(all_sources)\n", + "\n", + " try:\n", + " im = Image.open(src).convert(\"RGB\")\n", + " w, h = im.size\n", + "\n", + " scale = target_h / h\n", + " new_w = int(w * scale)\n", + "\n", + " im = im.resize((new_w, target_h), Image.LANCZOS)\n", + "\n", + " # overlap\n", + " if x > 0:\n", + " x -= int(new_w * overlap_ratio)\n", + "\n", + " canvas.paste(im, (x, 0))\n", + " x += new_w\n", + "\n", + " except:\n", + " continue\n", + "\n", + " return canvas\n", + "\n", + "# ────────────────────────────────────────────────\n", + "# Calculate required width\n", + "# ────────────────────────────────────────────────\n", + "\n", + "overlap_ratio = overlap_percent / 100.0\n", + "\n", + "avg_step = (min_step_ratio + max_step_ratio) / 2\n", + "estimated_width = int(num_frames * INNER_SIZE * avg_step * 1.2)\n", + "\n", + "print(\"Building row width:\", estimated_width)\n", + "\n", + "row_img = build_row_until_width(\n", + " all_sources,\n", + " INNER_SIZE,\n", + " overlap_ratio,\n", + " estimated_width\n", + ")\n", + "\n", + "row_np = np.array(row_img)\n", + "row_h, row_w = row_np.shape[:2]\n", + "\n", + "# ────────────────────────────────────────────────\n", + "# Generate frames (NO distortion)\n", + "# ────────────────────────────────────────────────\n", + "\n", + "frame_idx = 0\n", + "x_cursor = 0\n", + "\n", + "while x_cursor + INNER_SIZE <= row_w and frame_idx < num_frames:\n", + "\n", + " step = random.randint(\n", + " int(INNER_SIZE * min_step_ratio),\n", + " int(INNER_SIZE * max_step_ratio)\n", + " )\n", + "\n", + " crop = row_np[:, x_cursor:x_cursor + INNER_SIZE]\n", + "\n", + " final = Image.new(\"RGB\", (FRAME_SIZE, FRAME_SIZE), BORDER_COLOR)\n", + " final.paste(Image.fromarray(crop), (border_width, border_width))\n", + "\n", + " fname = f\"frame_{frame_idx:04d}.jpg\"\n", + " final.save(os.path.join(output_dir, fname), \"JPEG\", quality=90)\n", + "\n", + " frame_idx += 1\n", + " x_cursor += step\n", + "\n", + " if frame_idx % 50 == 0:\n", + " print(frame_idx, \"frames done\")\n", + "\n", + "print(\"Finished:\", frame_idx)\n", + "\n", + "# ────────────────────────────────────────────────\n", + "# Save ZIP\n", + "# ────────────────────────────────────────────────\n", + "\n", + "if save_to_google_drive and drive_mounted:\n", + "\n", + " zip_path = \"/content/output.zip\"\n", + " drive_path = os.path.join(drive_output_dir, \"vertical_slices.zip\")\n", + "\n", + " with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zf:\n", + " for f in os.listdir(output_dir):\n", + " if f.endswith(\".jpg\"):\n", + " zf.write(os.path.join(output_dir, f), arcname=f)\n", + "\n", + " !cp -f \"{zip_path}\" \"{drive_path}\"\n", + "\n", + " print(\"Saved to Drive:\", drive_path)" + ] + }, + { + "cell_type": "markdown", + "source": [ + "# Done!\n", + "\n", + "In the zip file /content/drive/MyDrive/vertical_slices_output/vertical_slices.zip , there you will find 100 image composites to choose for lora training\n", + "\n", + "//-----//" + ], + "metadata": { + "id": "tJlvhf9xDmA7" + } + } + ], + "metadata": { + "colab": { + "provenance": [], + "collapsed_sections": [ + "Mj8UDNOyqdKL", + "TEupY-WNeMHu", + "7eeX3_qpYpwl", + "s7R3l3-pY5W7", + "4PjK9a8Sni3A", + "kVAe29swHo4I" + ], + "gpuType": "T4" + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + }, + "accelerator": "GPU", + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "5fb522aff98949e4ae7df3c20ed54703": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HBoxModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HBoxModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HBoxView", + "box_style": "", + "children": [ + "IPY_MODEL_28d8bb0a08104a25b440c5d5e8a9bd0f", + "IPY_MODEL_b41a3725067646cf9a3c60ccefc64a97", + "IPY_MODEL_8a09831ec0e84884b086df43f593ce11" + ], + "layout": "IPY_MODEL_f95662023f5e45c99c4ae704a8c539e9" + } + }, + "28d8bb0a08104a25b440c5d5e8a9bd0f": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HTMLModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HTMLModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HTMLView", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_4c06cd79dd7647658d93120b1bf42e28", + "placeholder": "​", + "style": "IPY_MODEL_ac3e92d8fb1944ff8d93d27092925b35", + "value": "model_index.json: 100%" + } + }, + "b41a3725067646cf9a3c60ccefc64a97": { + "model_module": "@jupyter-widgets/controls", + "model_name": "FloatProgressModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "FloatProgressModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "ProgressView", + "bar_style": "success", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_5f78e9e6854b4ff183f47f4b2a418608", + "max": 509, + "min": 0, + "orientation": "horizontal", + "style": "IPY_MODEL_9e103e65b32b4ad0abaa512f97b1ee3c", + "value": 509 + } + }, + "8a09831ec0e84884b086df43f593ce11": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HTMLModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HTMLModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HTMLView", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_c078ccfc70c446a8b9ca506483ba1b0d", + "placeholder": "​", + "style": "IPY_MODEL_de393e6b05c14f589e05e2d79968cdfd", + "value": " 509/509 [00:00<00:00, 26.9kB/s]" + } + }, + "f95662023f5e45c99c4ae704a8c539e9": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "4c06cd79dd7647658d93120b1bf42e28": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "ac3e92d8fb1944ff8d93d27092925b35": { + "model_module": "@jupyter-widgets/controls", + "model_name": "DescriptionStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "DescriptionStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "" + } + }, + "5f78e9e6854b4ff183f47f4b2a418608": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "9e103e65b32b4ad0abaa512f97b1ee3c": { + "model_module": "@jupyter-widgets/controls", + "model_name": "ProgressStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "ProgressStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "bar_color": null, + "description_width": "" + } + }, + "c078ccfc70c446a8b9ca506483ba1b0d": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "de393e6b05c14f589e05e2d79968cdfd": { + "model_module": "@jupyter-widgets/controls", + "model_name": "DescriptionStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "DescriptionStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "" + } + }, + "9c3333d7b393436da41d607f997a1b87": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HBoxModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HBoxModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HBoxView", + "box_style": "", + "children": [ + "IPY_MODEL_bd64e1b1949a45b28592e9449acd5d71", + "IPY_MODEL_19d870948d314da5afc5010e889dc5ef", + "IPY_MODEL_6fd66e23535e470f81d12cbe17ac42e7" + ], + "layout": "IPY_MODEL_6929567cfb864542b34f87bb17af6999" + } + }, + "bd64e1b1949a45b28592e9449acd5d71": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HTMLModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HTMLModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HTMLView", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_62b87f3dd7904b8293416dc3f4315517", + "placeholder": "​", + "style": "IPY_MODEL_14d35378a8ea40daabf7582c24141d21", + "value": "Download complete: " + } + }, + "19d870948d314da5afc5010e889dc5ef": { + "model_module": "@jupyter-widgets/controls", + "model_name": "FloatProgressModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "FloatProgressModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "ProgressView", + "bar_style": "success", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_423922fbba2d4c3aa9314ba4331bd0a7", + "max": 1, + "min": 0, + "orientation": "horizontal", + "style": "IPY_MODEL_ad61dce7a32f40c38c5c0235620d329b", + "value": 1 + } + }, + "6fd66e23535e470f81d12cbe17ac42e7": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HTMLModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HTMLModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HTMLView", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_331f1f508d23434fb5f6cf4bd37975cc", + "placeholder": "​", + "style": "IPY_MODEL_c8684352f6e449168a6cdaddeaa3acfe", + "value": " 5.92G/? [00:55<00:00, 130MB/s]" + } + }, + "6929567cfb864542b34f87bb17af6999": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "62b87f3dd7904b8293416dc3f4315517": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "14d35378a8ea40daabf7582c24141d21": { + "model_module": "@jupyter-widgets/controls", + "model_name": "DescriptionStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "DescriptionStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "" + } + }, + "423922fbba2d4c3aa9314ba4331bd0a7": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": "20px" + } + }, + "ad61dce7a32f40c38c5c0235620d329b": { + "model_module": "@jupyter-widgets/controls", + "model_name": "ProgressStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "ProgressStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "bar_color": null, + "description_width": "" + } + }, + "331f1f508d23434fb5f6cf4bd37975cc": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "c8684352f6e449168a6cdaddeaa3acfe": { + "model_module": "@jupyter-widgets/controls", + "model_name": "DescriptionStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "DescriptionStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "" + } + }, + "491f54937819404d891578bc9cd659db": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HBoxModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HBoxModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HBoxView", + "box_style": "", + "children": [ + "IPY_MODEL_1da32d981bae4e6c8d4a384734ef39ef", + "IPY_MODEL_534220ea214d4048a93000e942f7991d", + "IPY_MODEL_10a62a86e8d04c9784f07ded08919a57" + ], + "layout": "IPY_MODEL_88346c0b0a374449a49911c395a6e001" + } + }, + "1da32d981bae4e6c8d4a384734ef39ef": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HTMLModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HTMLModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HTMLView", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_756a0c170b034a30a14e0c52f299e8af", + "placeholder": "​", + "style": "IPY_MODEL_1c4361237a0940b08d91fe9c36ddb6ff", + "value": "Fetching 11 files: 100%" + } + }, + "534220ea214d4048a93000e942f7991d": { + "model_module": "@jupyter-widgets/controls", + "model_name": "FloatProgressModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "FloatProgressModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "ProgressView", + "bar_style": "success", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_6b960da08bc64275b283ff2de3fbf864", + "max": 11, + "min": 0, + "orientation": "horizontal", + "style": "IPY_MODEL_eb57d6161b194692863969ca77a44f27", + "value": 11 + } + }, + "10a62a86e8d04c9784f07ded08919a57": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HTMLModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HTMLModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HTMLView", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_0a7a32e457f144b5b247559b5efd1855", + "placeholder": "​", + "style": "IPY_MODEL_ef720746be424a98944112b58cb0f00a", + "value": " 11/11 [00:54<00:00, 16.15s/it]" + } + }, + "88346c0b0a374449a49911c395a6e001": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "756a0c170b034a30a14e0c52f299e8af": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "1c4361237a0940b08d91fe9c36ddb6ff": { + "model_module": "@jupyter-widgets/controls", + "model_name": "DescriptionStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "DescriptionStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "" + } + }, + "6b960da08bc64275b283ff2de3fbf864": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "eb57d6161b194692863969ca77a44f27": { + "model_module": "@jupyter-widgets/controls", + "model_name": "ProgressStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "ProgressStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "bar_color": null, + "description_width": "" + } + }, + "0a7a32e457f144b5b247559b5efd1855": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "ef720746be424a98944112b58cb0f00a": { + "model_module": "@jupyter-widgets/controls", + "model_name": "DescriptionStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "DescriptionStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "" + } + }, + "d74d70d64c43401d9636797bb5405ab9": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HBoxModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HBoxModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HBoxView", + "box_style": "", + "children": [ + "IPY_MODEL_dbeaa864d98645f083939873f2e1c64e", + "IPY_MODEL_4d162183fe494f5e8589f2efcb3b709c", + "IPY_MODEL_fed04e5e9f63488f97b780dc2599c0ab" + ], + "layout": "IPY_MODEL_49726df6963e484f80dccd9dad3f561d" + } + }, + "dbeaa864d98645f083939873f2e1c64e": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HTMLModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HTMLModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HTMLView", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_b668d6c9da30444ba481764f58a1d613", + "placeholder": "​", + "style": "IPY_MODEL_aa4e6608fffd411ba0897d6106b4f551", + "value": "Loading pipeline components...: 100%" + } + }, + "4d162183fe494f5e8589f2efcb3b709c": { + "model_module": "@jupyter-widgets/controls", + "model_name": "FloatProgressModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "FloatProgressModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "ProgressView", + "bar_style": "success", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_1dce4b0d95d1452d982d9b6fb07c0f90", + "max": 5, + "min": 0, + "orientation": "horizontal", + "style": "IPY_MODEL_cfdd467912d54b2e8a72059ae9cacdc9", + "value": 5 + } + }, + "fed04e5e9f63488f97b780dc2599c0ab": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HTMLModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HTMLModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HTMLView", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_d0848635653141028bb665cf58ba412b", + "placeholder": "​", + "style": "IPY_MODEL_0a0e651f0f7a470fbca8662664c115fc", + "value": " 5/5 [00:21<00:00,  3.78s/it]" + } + }, + "49726df6963e484f80dccd9dad3f561d": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "b668d6c9da30444ba481764f58a1d613": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "aa4e6608fffd411ba0897d6106b4f551": { + "model_module": "@jupyter-widgets/controls", + "model_name": "DescriptionStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "DescriptionStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "" + } + }, + "1dce4b0d95d1452d982d9b6fb07c0f90": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "cfdd467912d54b2e8a72059ae9cacdc9": { + "model_module": "@jupyter-widgets/controls", + "model_name": "ProgressStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "ProgressStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "bar_color": null, + "description_width": "" + } + }, + "d0848635653141028bb665cf58ba412b": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "0a0e651f0f7a470fbca8662664c115fc": { + "model_module": "@jupyter-widgets/controls", + "model_name": "DescriptionStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "DescriptionStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "" + } + }, + "59b3aee270954902bba4c2bebec11683": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HBoxModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HBoxModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HBoxView", + "box_style": "", + "children": [ + "IPY_MODEL_1dbdd5a0e7ac47ccbedf8e7926abfe7c", + "IPY_MODEL_f1738bed749c4414b566a963b2379b21", + "IPY_MODEL_e5e2932e6e654e44a5b6f6d0b181d288" + ], + "layout": "IPY_MODEL_84a98b60fac441589d63bd86227dc17d" + } + }, + "1dbdd5a0e7ac47ccbedf8e7926abfe7c": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HTMLModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HTMLModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HTMLView", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_86a0b89247cc41bfa4bc751d2d8eff53", + "placeholder": "​", + "style": "IPY_MODEL_9861f89efbaa432c86ea381968338451", + "value": "Loading weights: 100%" + } + }, + "f1738bed749c4414b566a963b2379b21": { + "model_module": "@jupyter-widgets/controls", + "model_name": "FloatProgressModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "FloatProgressModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "ProgressView", + "bar_style": "success", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_28155ec9896843528718308d0c47a839", + "max": 901, + "min": 0, + "orientation": "horizontal", + "style": "IPY_MODEL_7d96df2110f64ef4b572f2c8a57aaa43", + "value": 901 + } + }, + "e5e2932e6e654e44a5b6f6d0b181d288": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HTMLModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HTMLModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HTMLView", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_6eb73b9d073742af9ddd59f54ff56841", + "placeholder": "​", + "style": "IPY_MODEL_a842e265159542fba4edb2f61a1b6a86", + "value": " 901/901 [00:03<00:00, 579.16it/s, Materializing param=model.norm.weight]" + } + }, + "84a98b60fac441589d63bd86227dc17d": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "86a0b89247cc41bfa4bc751d2d8eff53": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "9861f89efbaa432c86ea381968338451": { + "model_module": "@jupyter-widgets/controls", + "model_name": "DescriptionStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "DescriptionStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "" + } + }, + "28155ec9896843528718308d0c47a839": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "7d96df2110f64ef4b572f2c8a57aaa43": { + "model_module": "@jupyter-widgets/controls", + "model_name": "ProgressStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "ProgressStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "bar_color": null, + "description_width": "" + } + }, + "6eb73b9d073742af9ddd59f54ff56841": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "a842e265159542fba4edb2f61a1b6a86": { + "model_module": "@jupyter-widgets/controls", + "model_name": "DescriptionStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "DescriptionStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "" + } + } + } + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file