Last active
April 28, 2022 13:44
-
-
Save dienhoa/9279b01674e0b341c9ae6c7c5b094771 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "id": "88f87ccc", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stderr", | |
| "output_type": "stream", | |
| "text": [ | |
| "/home/ubuntu/miniconda3/envs/midas/lib/python3.8/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", | |
| " from .autonotebook import tqdm as notebook_tqdm\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "import cv2\n", | |
| "import torch\n", | |
| "import urllib.request\n", | |
| "import matplotlib.pyplot as plt\n", | |
| "import plotly.express as px\n", | |
| "from plotly.subplots import make_subplots\n" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "id": "c2b8fd26", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stderr", | |
| "output_type": "stream", | |
| "text": [ | |
| "Using cache found in /home/ubuntu/.cache/torch/hub/intel-isl_MiDaS_master\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "model_type = \"DPT_Large\" # MiDaS v3 - Large (highest accuracy, slowest inference speed)\n", | |
| "#model_type = \"DPT_Hybrid\" # MiDaS v3 - Hybrid (medium accuracy, medium inference speed)\n", | |
| "#model_type = \"MiDaS_small\" # MiDaS v2.1 - Small (lowest accuracy, highest inference speed)\n", | |
| "\n", | |
| "midas = torch.hub.load(\"intel-isl/MiDaS\", model_type)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 3, | |
| "id": "78330d56", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "DPTDepthModel(\n", | |
| " (pretrained): Module(\n", | |
| " (model): VisionTransformer(\n", | |
| " (patch_embed): PatchEmbed(\n", | |
| " (proj): Conv2d(3, 1024, kernel_size=(16, 16), stride=(16, 16))\n", | |
| " (norm): Identity()\n", | |
| " )\n", | |
| " (pos_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (blocks): Sequential(\n", | |
| " (0): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (1): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (2): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (3): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (4): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (5): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (6): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (7): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (8): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (9): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (10): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (11): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (12): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (13): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (14): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (15): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (16): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (17): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (18): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (19): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (20): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (21): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (22): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " (23): Block(\n", | |
| " (norm1): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (attn): Attention(\n", | |
| " (qkv): Linear(in_features=1024, out_features=3072, bias=True)\n", | |
| " (attn_drop): Dropout(p=0.0, inplace=False)\n", | |
| " (proj): Linear(in_features=1024, out_features=1024, bias=True)\n", | |
| " (proj_drop): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " (drop_path): Identity()\n", | |
| " (norm2): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (mlp): Mlp(\n", | |
| " (fc1): Linear(in_features=1024, out_features=4096, bias=True)\n", | |
| " (act): GELU()\n", | |
| " (drop1): Dropout(p=0.0, inplace=False)\n", | |
| " (fc2): Linear(in_features=4096, out_features=1024, bias=True)\n", | |
| " (drop2): Dropout(p=0.0, inplace=False)\n", | |
| " )\n", | |
| " )\n", | |
| " )\n", | |
| " (norm): LayerNorm((1024,), eps=1e-06, elementwise_affine=True)\n", | |
| " (pre_logits): Identity()\n", | |
| " (head): Linear(in_features=1024, out_features=1000, bias=True)\n", | |
| " )\n", | |
| " (act_postprocess1): Sequential(\n", | |
| " (0): ProjectReadout(\n", | |
| " (project): Sequential(\n", | |
| " (0): Linear(in_features=2048, out_features=1024, bias=True)\n", | |
| " (1): GELU()\n", | |
| " )\n", | |
| " )\n", | |
| " (1): Transpose()\n", | |
| " (2): Unflatten(dim=2, unflattened_size=torch.Size([24, 24]))\n", | |
| " (3): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1))\n", | |
| " (4): ConvTranspose2d(256, 256, kernel_size=(4, 4), stride=(4, 4))\n", | |
| " )\n", | |
| " (act_postprocess2): Sequential(\n", | |
| " (0): ProjectReadout(\n", | |
| " (project): Sequential(\n", | |
| " (0): Linear(in_features=2048, out_features=1024, bias=True)\n", | |
| " (1): GELU()\n", | |
| " )\n", | |
| " )\n", | |
| " (1): Transpose()\n", | |
| " (2): Unflatten(dim=2, unflattened_size=torch.Size([24, 24]))\n", | |
| " (3): Conv2d(1024, 512, kernel_size=(1, 1), stride=(1, 1))\n", | |
| " (4): ConvTranspose2d(512, 512, kernel_size=(2, 2), stride=(2, 2))\n", | |
| " )\n", | |
| " (act_postprocess3): Sequential(\n", | |
| " (0): ProjectReadout(\n", | |
| " (project): Sequential(\n", | |
| " (0): Linear(in_features=2048, out_features=1024, bias=True)\n", | |
| " (1): GELU()\n", | |
| " )\n", | |
| " )\n", | |
| " (1): Transpose()\n", | |
| " (2): Unflatten(dim=2, unflattened_size=torch.Size([24, 24]))\n", | |
| " (3): Conv2d(1024, 1024, kernel_size=(1, 1), stride=(1, 1))\n", | |
| " )\n", | |
| " (act_postprocess4): Sequential(\n", | |
| " (0): ProjectReadout(\n", | |
| " (project): Sequential(\n", | |
| " (0): Linear(in_features=2048, out_features=1024, bias=True)\n", | |
| " (1): GELU()\n", | |
| " )\n", | |
| " )\n", | |
| " (1): Transpose()\n", | |
| " (2): Unflatten(dim=2, unflattened_size=torch.Size([24, 24]))\n", | |
| " (3): Conv2d(1024, 1024, kernel_size=(1, 1), stride=(1, 1))\n", | |
| " (4): Conv2d(1024, 1024, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n", | |
| " )\n", | |
| " )\n", | |
| " (scratch): Module(\n", | |
| " (layer1_rn): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n", | |
| " (layer2_rn): Conv2d(512, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n", | |
| " (layer3_rn): Conv2d(1024, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n", | |
| " (layer4_rn): Conv2d(1024, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n", | |
| " (refinenet1): FeatureFusionBlock_custom(\n", | |
| " (out_conv): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1))\n", | |
| " (resConfUnit1): ResidualConvUnit_custom(\n", | |
| " (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (activation): ReLU()\n", | |
| " (skip_add): FloatFunctional(\n", | |
| " (activation_post_process): Identity()\n", | |
| " )\n", | |
| " )\n", | |
| " (resConfUnit2): ResidualConvUnit_custom(\n", | |
| " (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (activation): ReLU()\n", | |
| " (skip_add): FloatFunctional(\n", | |
| " (activation_post_process): Identity()\n", | |
| " )\n", | |
| " )\n", | |
| " (skip_add): FloatFunctional(\n", | |
| " (activation_post_process): Identity()\n", | |
| " )\n", | |
| " )\n", | |
| " (refinenet2): FeatureFusionBlock_custom(\n", | |
| " (out_conv): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1))\n", | |
| " (resConfUnit1): ResidualConvUnit_custom(\n", | |
| " (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (activation): ReLU()\n", | |
| " (skip_add): FloatFunctional(\n", | |
| " (activation_post_process): Identity()\n", | |
| " )\n", | |
| " )\n", | |
| " (resConfUnit2): ResidualConvUnit_custom(\n", | |
| " (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (activation): ReLU()\n", | |
| " (skip_add): FloatFunctional(\n", | |
| " (activation_post_process): Identity()\n", | |
| " )\n", | |
| " )\n", | |
| " (skip_add): FloatFunctional(\n", | |
| " (activation_post_process): Identity()\n", | |
| " )\n", | |
| " )\n", | |
| " (refinenet3): FeatureFusionBlock_custom(\n", | |
| " (out_conv): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1))\n", | |
| " (resConfUnit1): ResidualConvUnit_custom(\n", | |
| " (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (activation): ReLU()\n", | |
| " (skip_add): FloatFunctional(\n", | |
| " (activation_post_process): Identity()\n", | |
| " )\n", | |
| " )\n", | |
| " (resConfUnit2): ResidualConvUnit_custom(\n", | |
| " (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (activation): ReLU()\n", | |
| " (skip_add): FloatFunctional(\n", | |
| " (activation_post_process): Identity()\n", | |
| " )\n", | |
| " )\n", | |
| " (skip_add): FloatFunctional(\n", | |
| " (activation_post_process): Identity()\n", | |
| " )\n", | |
| " )\n", | |
| " (refinenet4): FeatureFusionBlock_custom(\n", | |
| " (out_conv): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1))\n", | |
| " (resConfUnit1): ResidualConvUnit_custom(\n", | |
| " (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (activation): ReLU()\n", | |
| " (skip_add): FloatFunctional(\n", | |
| " (activation_post_process): Identity()\n", | |
| " )\n", | |
| " )\n", | |
| " (resConfUnit2): ResidualConvUnit_custom(\n", | |
| " (conv1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (activation): ReLU()\n", | |
| " (skip_add): FloatFunctional(\n", | |
| " (activation_post_process): Identity()\n", | |
| " )\n", | |
| " )\n", | |
| " (skip_add): FloatFunctional(\n", | |
| " (activation_post_process): Identity()\n", | |
| " )\n", | |
| " )\n", | |
| " (output_conv): Sequential(\n", | |
| " (0): Conv2d(256, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (1): Interpolate()\n", | |
| " (2): Conv2d(128, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", | |
| " (3): ReLU(inplace=True)\n", | |
| " (4): Conv2d(32, 1, kernel_size=(1, 1), stride=(1, 1))\n", | |
| " (5): ReLU(inplace=True)\n", | |
| " (6): Identity()\n", | |
| " )\n", | |
| " )\n", | |
| ")" | |
| ] | |
| }, | |
| "execution_count": 3, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "device = torch.device(\"cuda\") if torch.cuda.is_available() else torch.device(\"cpu\")\n", | |
| "midas.to(device)\n", | |
| "midas.eval()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "id": "a221abed", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "device(type='cuda')" | |
| ] | |
| }, | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "device" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 5, | |
| "id": "3144d493", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stderr", | |
| "output_type": "stream", | |
| "text": [ | |
| "Using cache found in /home/ubuntu/.cache/torch/hub/intel-isl_MiDaS_master\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "midas_transforms = torch.hub.load(\"intel-isl/MiDaS\", \"transforms\")\n", | |
| "\n", | |
| "if model_type == \"DPT_Large\" or model_type == \"DPT_Hybrid\":\n", | |
| " transform = midas_transforms.dpt_transform\n", | |
| "else:\n", | |
| " transform = midas_transforms.small_transform" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 6, | |
| "id": "71661559", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "from fastai.vision.all import *" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 7, | |
| "id": "c6dc4dbf", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "src_folder = Path('./DS_video/no_fire_imgs_full/')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 8, | |
| "id": "cba3ecd8", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "video_paths = src_folder.ls()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 9, | |
| "id": "40fc182b", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "(#59) [Path('DS_video/no_fire_imgs_full/597_seq1430_1502'),Path('DS_video/no_fire_imgs_full/597_seq563_740'),Path('DS_video/no_fire_imgs_full/30_seq0_665'),Path('DS_video/no_fire_imgs_full/705_seq0_1147'),Path('DS_video/no_fire_imgs_full/173_seq0_745'),Path('DS_video/no_fire_imgs_full/758_seq0_1328'),Path('DS_video/no_fire_imgs_full/168_seq0_1155'),Path('DS_video/no_fire_imgs_full/686_seq6_1502'),Path('DS_video/no_fire_imgs_full/561_seq0_1376'),Path('DS_video/no_fire_imgs_full/52_seq0_1164')...]" | |
| ] | |
| }, | |
| "execution_count": 9, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "video_paths" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 10, | |
| "id": "80a97740", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "imgs = [video/'10.jpg' for video in video_paths]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 11, | |
| "id": "a9637ccf", | |
| "metadata": { | |
| "scrolled": true | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "[Path('DS_video/no_fire_imgs_full/597_seq1430_1502/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/597_seq563_740/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/30_seq0_665/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/705_seq0_1147/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/173_seq0_745/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/758_seq0_1328/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/168_seq0_1155/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/686_seq6_1502/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/561_seq0_1376/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/52_seq0_1164/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/556_seq940_963/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/62_seq0_774/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/260_seq0_93/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/264_seq0_291/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/298_seq0_326/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/246_seq737_938/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/556_seq965_1502/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/260_seq573_759/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/173_seq751_776/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/216_seq1036_1277/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/334_seq0_1061/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/597_seq0_562/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/881_seq0_1204/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/173_seq777_887/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/173_seq1029_1092/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/246_seq939_950/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/224_seq296_327/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/26_seq510_859/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/262_seq0_588/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/369_seq1341_1391/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/318_seq0_534/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/298_seq366_383/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/502_seq0_1072/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/224_seq0_276/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/367_seq121_1271/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/315_seq0_472/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/26_seq0_484/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/793_seq0_1057/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/369_seq0_1241/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/240_seq0_789/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/894_seq1_1502/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/387_seq513_721/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/712_seq0_1293/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/387_seq0_512/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/597_seq1043_1131/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/741_seq0_162/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/398_seq704_721/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/177_seq0_1311/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/556_seq841_931/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/601_seq0_1253/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/284_seq0_214/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/696_seq266_276/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/344_seq775_1501/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/695_seq0_102/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/35_seq0_58/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/348_seq0_904/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/216_seq0_861/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/705_seq1169_1502/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/607_seq0_1502/10.jpg')]" | |
| ] | |
| }, | |
| "execution_count": 11, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "imgs" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 12, | |
| "id": "0bc38f72", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "folder_dest = Path('./DS_video/no_fire_depth_imgs/')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 13, | |
| "id": "72532278", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "img_path = imgs[0]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 14, | |
| "id": "bc3290e8", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "Path('DS_video/no_fire_imgs_full/597_seq1430_1502/10.jpg')" | |
| ] | |
| }, | |
| "execution_count": 14, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "img_path" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 16, | |
| "id": "c6aea077", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "output_path = str(folder_dest/f'{img_path.parent.name}.jpg')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 17, | |
| "id": "6e00dbe9", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "'DS_video/no_fire_depth_imgs/597_seq1430_1502.jpg'" | |
| ] | |
| }, | |
| "execution_count": 17, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "output_path" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "728ea009", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "for img_path in imgs:\n", | |
| " img = cv2.imread(str(img_path))\n", | |
| " img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n", | |
| " input_batch = transform(img).to(device)\n", | |
| " with torch.no_grad():\n", | |
| " prediction = midas(input_batch)\n", | |
| " prediction = torch.nn.functional.interpolate(\n", | |
| " prediction.unsqueeze(1),\n", | |
| " size=img.shape[:2],\n", | |
| " mode=\"bicubic\",\n", | |
| " align_corners=False,\n", | |
| " ).squeeze()\n", | |
| "\n", | |
| " output = prediction.cpu().numpy()\n", | |
| " output = (output/40*255).astype(int)\n", | |
| "# (folder_dest/img_path.parent.name).mkdir(exist_ok=True)\n", | |
| " output_path = str(folder_dest/f'{img_path.parent.name}.jpg')\n", | |
| " cv2.imwrite(output_path, output)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 27, | |
| "id": "11886e70", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "nb_test=5\n", | |
| "start=6\n", | |
| "imgs_test = imgs[start:start+nb_test]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 34, | |
| "id": "97254b60", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "[Path('DS_video/no_fire_imgs_full/597_seq1430_1502/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/597_seq563_740/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/30_seq0_665/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/705_seq0_1147/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/173_seq0_745/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/758_seq0_1328/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/168_seq0_1155/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/686_seq6_1502/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/561_seq0_1376/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/52_seq0_1164/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/556_seq940_963/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/62_seq0_774/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/260_seq0_93/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/264_seq0_291/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/298_seq0_326/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/246_seq737_938/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/556_seq965_1502/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/260_seq573_759/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/173_seq751_776/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/216_seq1036_1277/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/334_seq0_1061/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/597_seq0_562/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/881_seq0_1204/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/173_seq777_887/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/173_seq1029_1092/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/246_seq939_950/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/224_seq296_327/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/26_seq510_859/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/262_seq0_588/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/369_seq1341_1391/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/318_seq0_534/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/298_seq366_383/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/502_seq0_1072/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/224_seq0_276/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/367_seq121_1271/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/315_seq0_472/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/26_seq0_484/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/793_seq0_1057/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/369_seq0_1241/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/240_seq0_789/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/894_seq1_1502/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/387_seq513_721/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/712_seq0_1293/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/387_seq0_512/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/597_seq1043_1131/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/741_seq0_162/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/398_seq704_721/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/177_seq0_1311/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/556_seq841_931/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/601_seq0_1253/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/284_seq0_214/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/696_seq266_276/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/344_seq775_1501/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/695_seq0_102/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/35_seq0_58/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/348_seq0_904/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/216_seq0_861/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/705_seq1169_1502/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/607_seq0_1502/10.jpg')]" | |
| ] | |
| }, | |
| "execution_count": 34, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "imgs" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 33, | |
| "id": "098ba990", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "[Path('DS_video/no_fire_imgs_full/168_seq0_1155/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/686_seq6_1502/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/561_seq0_1376/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/52_seq0_1164/10.jpg'),\n", | |
| " Path('DS_video/no_fire_imgs_full/556_seq940_963/10.jpg')]" | |
| ] | |
| }, | |
| "execution_count": 33, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "imgs_test" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 28, | |
| "id": "df047aaa", | |
| "metadata": { | |
| "scrolled": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "application/vnd.plotly.v1+json": { | |
| "config": { | |
| "plotlyServerURL": "https://plot.ly" | |
| }, | |
| "data": [ | |
| { | |
| "hovertemplate": "x: %{x}<br>y: %{y}<br>color: [%{z[0]}, %{z[1]}, %{z[2]}]<extra></extra>", | |
| "name": "0", |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment