{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Unit Test for DeepLabv3" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "ROOT_DIR = \"/home/tiger/projects/GeneFace_private/\"\n", "os.chdir(ROOT_DIR)\n", "os.environ['PYTHONPATH'] = ROOT_DIR" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from modules.img2plane.deeplabv3 import DeepLabV3\n", "\n", "model = DeepLabV3(decoder_channels=256, in_channels=3+2)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "256" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.decoder.out_channels" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "torch.Size([2, 256, 64, 64])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import torch\n", "x = torch.randn([2,3+2,512,512])\n", "y = model(x)\n", "\n", "y.shape" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Unit Test for High Resolution Image Encoder" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "ROOT_DIR = \"/home/tiger/projects/GeneFace_private/\"\n", "os.chdir(ROOT_DIR)\n", "os.environ['PYTHONPATH'] = ROOT_DIR" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "from modules.img2plane.simple_encoders.high_resolution_encoder import HighResoEncoder\n", "model = HighResoEncoder()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "torch.Size([2, 96, 256, 256])" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import torch\n", "x = torch.randn([2, 5, 512, 512])\n", "y = model(x)\n", "\n", "y.shape" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Unit Test for ViT" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "ROOT_DIR = \"/home/tiger/projects/GeneFace_private/\"\n", "os.chdir(ROOT_DIR)\n", "os.environ['PYTHONPATH'] = ROOT_DIR" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/local/lib/python3.9/dist-packages/tqdm/auto.py:21: 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": [ "from modules.img2plane.segformer import LowResolutionViT, TriplanePredictorViT\n", "\n", "model1 = LowResolutionViT()\n", "model2 = TriplanePredictorViT()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "torch.Size([2, 96, 256, 256])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import torch\n", "deeplab_out = torch.randn([2, 256, 64, 64])\n", "y1 = model1(deeplab_out) # [B, C=96, H=256, W=256]\n", "\n", "y1.shape" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "torch.Size([2, 96, 256, 256])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "high_reso_out = torch.randn([2, 96, 256, 256])\n", "y2 = model2(y1, high_reso_out)\n", "\n", "y2.shape" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Unit Test for the Img2Plane Predictor" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "ROOT_DIR = \"/home/tiger/projects/GeneFace_private/\"\n", "os.chdir(ROOT_DIR)\n", "os.environ['PYTHONPATH'] = ROOT_DIR" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/local/lib/python3.9/dist-packages/tqdm/auto.py:21: 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": [ "from modules.img2plane.img2plane_model import Img2PlaneModel\n", "\n", "model = Img2PlaneModel()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "torch.Size([2, 96, 256, 256])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import torch\n", "x = torch.randn([2, 3, 512, 512])\n", "\n", "y = model(x)\n", "\n", "y.shape" ] } ], "metadata": { "kernelspec": { "display_name": "venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.2" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }