From 8bdffdf7e5534d0ddf6e2cefdd2ecef005494c49 Mon Sep 17 00:00:00 2001 From: Parth Patel Date: Sun, 2 Aug 2020 13:12:27 +0200 Subject: [PATCH 1/9] Update train.py --- train.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/train.py b/train.py index bd2ae44..577d8d2 100644 --- a/train.py +++ b/train.py @@ -24,9 +24,9 @@ def parse_arguments(): parser.add_argument('--wd', default=0., help='L2 Weight decay', type=float) parser.add_argument('--img_size', default=256, help='Image size to be used for training', type=int) parser.add_argument('--aug', default=True, help='Whether to use Image augmentation', type=bool) - parser.add_argument('--n_worker', default=2, help='Number of workers to use for loading data', type=int) + parser.add_argument('--n_worker', default=2, help='Number of thread to use for loading data(uses RAM)', type=int) parser.add_argument('--test_interval', default=2, help='Number of epochs after which to test the weights', type=int) - parser.add_argument('--save_interval', default=None, help='Number of epochs after which to save the weights. If None, does not save', type=int) + parser.add_argument('--save_interval', default=2, help='Number of epochs after which to save the weights. If None, does not save', type=int) parser.add_argument('--save_opt', default=False, help='Whether to save optimizer along with model weights or not', type=bool) parser.add_argument('--log_interval', default=250, help='Logging interval (in #batches)', type=int) parser.add_argument('--res_mod', default=None, help='Path to the model to resume from', type=str) @@ -119,7 +119,9 @@ def train(self): ca_act_reg)) # Validation + if epoch % self.test_interval == 0 or epoch % self.save_interval == 0: + te_avg_loss, te_acc, te_pre, te_rec, te_mae = self.test() mod_chkpt = {'epoch': epoch, 'test_mae' : float(te_mae), @@ -140,21 +142,22 @@ def train(self): # Save the best model if te_mae < best_test_mae: + best_test_mae = te_mae - torch.save(mod_chkpt, self.model_path + 'weights/best-model_epoch-{:03}_mae-{:.4f}_loss-{:.4f}.pth'. + torch.save(mod_chkpt, self.model_path + '/weights/best-model_epoch-{:03}_mae-{:.4f}_loss-{:.4f}.pth'. format(epoch, best_test_mae, te_avg_loss)) if self.save_opt: - torch.save(opt_chkpt, self.model_path + 'optimizers/best-opt_epoch-{:03}_mae-{:.4f}_loss-{:.4f}.pth'. + torch.save(opt_chkpt, self.model_path + '/optimizers/best-opt_epoch-{:03}_mae-{:.4f}_loss-{:.4f}.pth'. format(epoch, best_test_mae, te_avg_loss)) print('Best Model Saved !!!\n') continue # Save model at regular intervals if self.save_interval is not None and epoch % self.save_interval == 0: - torch.save(mod_chkpt, self.model_path + 'weights/model_epoch-{:03}_mae-{:.4f}_loss-{:.4f}.pth'. + torch.save(mod_chkpt, self.model_path + '/weights/model_epoch-{:03}_mae-{:.4f}_loss-{:.4f}.pth'. format(epoch, te_mae, te_avg_loss)) if self.save_opt: - torch.save(opt_chkpt, self.model_path + 'optimizers/opt_epoch-{:03}_mae-{:.4f}_loss-{:.4f}.pth'. + torch.save(opt_chkpt, self.model_path + '/optimizers/opt_epoch-{:03}_mae-{:.4f}_loss-{:.4f}.pth'. format(epoch, best_test_mae, te_avg_loss)) print('Model Saved !!!\n') continue From 5d062717a049c612d4a7e538cff535cb2381c62c Mon Sep 17 00:00:00 2001 From: Parth Patel Date: Sun, 2 Aug 2020 15:00:50 +0200 Subject: [PATCH 2/9] Update train.py --- train.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/train.py b/train.py index 577d8d2..a93f010 100644 --- a/train.py +++ b/train.py @@ -14,7 +14,7 @@ from src.dataloader import SODLoader from src.model import SODModel from src.loss import EdgeSaliencyLoss - +import math def parse_arguments(): parser = argparse.ArgumentParser(description='Parameters to train your model.') @@ -119,8 +119,8 @@ def train(self): ca_act_reg)) # Validation - - if epoch % self.test_interval == 0 or epoch % self.save_interval == 0: + + if math.fmod(epoch, self.test_interval) == 0 or math.fmod(epoch, self.save_interval) == 0: te_avg_loss, te_acc, te_pre, te_rec, te_mae = self.test() mod_chkpt = {'epoch': epoch, From 7bc1f4ce6c66a9b1c7cd8265f1a1e12839039ac3 Mon Sep 17 00:00:00 2001 From: Parth Patel Date: Tue, 4 Aug 2020 18:19:34 +0200 Subject: [PATCH 3/9] Update inference.py --- inference.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/inference.py b/inference.py index 9ed931c..ea5ed74 100644 --- a/inference.py +++ b/inference.py @@ -17,10 +17,10 @@ def parse_arguments(): parser = argparse.ArgumentParser(description='Parameters to train your model.') - parser.add_argument('--imgs_folder', default='./data/DUTS/DUTS-TE/DUTS-TE-Image', help='Path to folder containing images', type=str) - parser.add_argument('--model_path', default='/home/tarasha/Projects/sairajk/saliency/SOD_2/models/0.7_wbce_w0-1_w1-1.12/best_epoch-138_acc-0.9107_loss-0.1300.pt', help='Path to model', type=str) + parser.add_argument('--imgs_folder', default='/content/test', help='Path to folder containing images', type=str) + parser.add_argument('--model_path', default='/content/drive/My Drive/Colab Notebooks/models/model_epoch-008_mae-0.1553_loss-0.3755.pth', help='Path to model', type=str) parser.add_argument('--use_gpu', default=True, help='Whether to use GPU or not', type=bool) - parser.add_argument('--img_size', default=256, help='Image size to be used', type=int) + parser.add_argument('--img_size', default=720, help='Image size to be used', type=int) parser.add_argument('--bs', default=24, help='Batch Size for testing', type=int) return parser.parse_args() @@ -59,9 +59,9 @@ def run_inference(args): pred_masks_round = np.squeeze(pred_masks.round().cpu().numpy(), axis=(0, 1)) print('Image :', batch_idx) - cv2.imshow('Input Image', img_np) - cv2.imshow('Generated Saliency Mask', pred_masks_raw) - cv2.imshow('Rounded-off Saliency Mask', pred_masks_round) + cv2.imwrite('/content/test/'+'Input Image'+ str(batch_idx) + '.png', img_np) + cv2.imwrite('/content/test/'+'Generated Saliency Mask'+ str(batch_idx) + '.png', pred_masks_raw) + cv2.imwrite('/content/test/'+'Rounded-off Saliency Mask'+ str(batch_idx) + '.png', pred_masks_round) key = cv2.waitKey(0) if key == ord('q'): @@ -101,5 +101,5 @@ def calculate_mae(args): if __name__ == '__main__': rt_args = parse_arguments() - calculate_mae(rt_args) - run_inference(rt_args) + #calculate_mae(rt_args) + run_inference(rt_args) \ No newline at end of file From f8254b4a5a82025215a658232e15917d2b23d7bf Mon Sep 17 00:00:00 2001 From: Parth Patel Date: Tue, 4 Aug 2020 18:22:41 +0200 Subject: [PATCH 4/9] Created using Colaboratory --- pyramid_train.ipynb | 141 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 pyramid_train.ipynb diff --git a/pyramid_train.ipynb b/pyramid_train.ipynb new file mode 100644 index 0000000..16885f8 --- /dev/null +++ b/pyramid_train.ipynb @@ -0,0 +1,141 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "pyramid train.ipynb", + "provenance": [], + "collapsed_sections": [], + "mount_file_id": "1v4ZKD8onuSrchfAXnvz1RE5IyNpn1Qe6", + "authorship_tag": "ABX9TyO/ulUHn4r2jO5XNZP1c/Mm" + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "accelerator": "GPU" + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "eartF9D1Mpvc", + "colab_type": "text" + }, + "source": [ + "**Pyramid-SD** Train" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "fdmwMZUEMf48", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 123 + }, + "outputId": "f4c2c469-fa1c-448b-b891-453bbde591cf" + }, + "source": [ + "!git clone https://github.com/parth15041995/Pyramid-SD_PyTorch.git" + ], + "execution_count": 1, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Cloning into 'Pyramid-SD_PyTorch'...\n", + "remote: Enumerating objects: 65, done.\u001b[K\n", + "remote: Counting objects: 100% (65/65), done.\u001b[K\n", + "remote: Compressing objects: 100% (56/56), done.\u001b[K\n", + "remote: Total 65 (delta 17), reused 19 (delta 5), pack-reused 0\u001b[K\n", + "Unpacking objects: 100% (65/65), done.\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "6GjSmDGuMocn", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "daa588ef-3298-4a2e-f0ac-db466a4f5ab9" + }, + "source": [ + "cd /content/Pyramid-SD_PyTorch" + ], + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "text": [ + "/content/Pyramid-SD_PyTorch\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "iDN207WOYEyF", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!cp '/content/drive/My Drive/DUTS.zip' /content/Pyramid-SD_PyTorch" + ], + "execution_count": 3, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "3wGdelkJLURT", + "colab_type": "code", + "colab": {} + }, + "source": [ + "import zipfile\n", + "with zipfile.ZipFile('DUTS.zip', 'r') as zip_ref:\n", + " zip_ref.extractall('./data')" + ], + "execution_count": 4, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "4eSjb56GL62g", + "colab_type": "code", + "colab": {} + }, + "source": [ + "%%shell\n", + "python train.py --epochs 10 --n_worker 56" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "pFe9TS-KsUxb", + "colab_type": "code", + "colab": {} + }, + "source": [ + "%%shell\n", + "python inference.py " + ], + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file From 7ecc9d30d4437374eed84543e66c578955fbcd6c Mon Sep 17 00:00:00 2001 From: Parth Patel Date: Thu, 6 Aug 2020 11:21:45 +0200 Subject: [PATCH 5/9] Update inference.py --- inference.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inference.py b/inference.py index ea5ed74..2f99e64 100644 --- a/inference.py +++ b/inference.py @@ -20,7 +20,7 @@ def parse_arguments(): parser.add_argument('--imgs_folder', default='/content/test', help='Path to folder containing images', type=str) parser.add_argument('--model_path', default='/content/drive/My Drive/Colab Notebooks/models/model_epoch-008_mae-0.1553_loss-0.3755.pth', help='Path to model', type=str) parser.add_argument('--use_gpu', default=True, help='Whether to use GPU or not', type=bool) - parser.add_argument('--img_size', default=720, help='Image size to be used', type=int) + parser.add_argument('--img_size', default=256, help='Image size to be used', type=int) parser.add_argument('--bs', default=24, help='Batch Size for testing', type=int) return parser.parse_args() From e7f21fe9ee3dd70d2fb423237e605a9d985026cd Mon Sep 17 00:00:00 2001 From: Parth Patel Date: Thu, 6 Aug 2020 11:21:49 +0200 Subject: [PATCH 6/9] Update .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1705a62..15ca79b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ __pycache__ -*/__pycache__ \ No newline at end of file +*/__pycache__ +.vscode/settings.json From a2cf915a83b34b4856d4b77a4a914726bfe98f35 Mon Sep 17 00:00:00 2001 From: Parth Patel Date: Mon, 14 Dec 2020 17:03:13 +0100 Subject: [PATCH 7/9] Created using Colaboratory --- pyramid_train.ipynb | 165 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 136 insertions(+), 29 deletions(-) diff --git a/pyramid_train.ipynb b/pyramid_train.ipynb index 16885f8..bfec7d3 100644 --- a/pyramid_train.ipynb +++ b/pyramid_train.ipynb @@ -6,8 +6,10 @@ "name": "pyramid train.ipynb", "provenance": [], "collapsed_sections": [], + "toc_visible": true, "mount_file_id": "1v4ZKD8onuSrchfAXnvz1RE5IyNpn1Qe6", - "authorship_tag": "ABX9TyO/ulUHn4r2jO5XNZP1c/Mm" + "authorship_tag": "ABX9TyNthtxYesufB5XHFxbMXj2E", + "include_colab_link": true }, "kernelspec": { "name": "python3", @@ -19,9 +21,18 @@ { "cell_type": "markdown", "metadata": { - "id": "eartF9D1Mpvc", + "id": "view-in-github", "colab_type": "text" }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "eartF9D1Mpvc" + }, "source": [ "**Pyramid-SD** Train" ] @@ -30,12 +41,10 @@ "cell_type": "code", "metadata": { "id": "fdmwMZUEMf48", - "colab_type": "code", "colab": { - "base_uri": "https://localhost:8080/", - "height": 123 + "base_uri": "https://localhost:8080/" }, - "outputId": "f4c2c469-fa1c-448b-b891-453bbde591cf" + "outputId": "d9483748-2036-4d1b-a375-a280315d156e" }, "source": [ "!git clone https://github.com/parth15041995/Pyramid-SD_PyTorch.git" @@ -46,11 +55,11 @@ "output_type": "stream", "text": [ "Cloning into 'Pyramid-SD_PyTorch'...\n", - "remote: Enumerating objects: 65, done.\u001b[K\n", - "remote: Counting objects: 100% (65/65), done.\u001b[K\n", - "remote: Compressing objects: 100% (56/56), done.\u001b[K\n", - "remote: Total 65 (delta 17), reused 19 (delta 5), pack-reused 0\u001b[K\n", - "Unpacking objects: 100% (65/65), done.\n" + "remote: Enumerating objects: 79, done.\u001b[K\n", + "remote: Counting objects: 100% (79/79), done.\u001b[K\n", + "remote: Compressing objects: 100% (66/66), done.\u001b[K\n", + "remote: Total 79 (delta 24), reused 27 (delta 8), pack-reused 0\u001b[K\n", + "Unpacking objects: 100% (79/79), done.\n" ], "name": "stdout" } @@ -60,12 +69,10 @@ "cell_type": "code", "metadata": { "id": "6GjSmDGuMocn", - "colab_type": "code", "colab": { - "base_uri": "https://localhost:8080/", - "height": 34 + "base_uri": "https://localhost:8080/" }, - "outputId": "daa588ef-3298-4a2e-f0ac-db466a4f5ab9" + "outputId": "2c334305-476f-4caf-c8cf-0e1b0fc670e3" }, "source": [ "cd /content/Pyramid-SD_PyTorch" @@ -84,9 +91,7 @@ { "cell_type": "code", "metadata": { - "id": "iDN207WOYEyF", - "colab_type": "code", - "colab": {} + "id": "iDN207WOYEyF" }, "source": [ "!cp '/content/drive/My Drive/DUTS.zip' /content/Pyramid-SD_PyTorch" @@ -97,9 +102,7 @@ { "cell_type": "code", "metadata": { - "id": "3wGdelkJLURT", - "colab_type": "code", - "colab": {} + "id": "3wGdelkJLURT" }, "source": [ "import zipfile\n", @@ -112,13 +115,11 @@ { "cell_type": "code", "metadata": { - "id": "4eSjb56GL62g", - "colab_type": "code", - "colab": {} + "id": "4eSjb56GL62g" }, "source": [ "%%shell\n", - "python train.py --epochs 10 --n_worker 56" + "python train.py --epochs 1 --n_worker 192" ], "execution_count": null, "outputs": [] @@ -126,16 +127,122 @@ { "cell_type": "code", "metadata": { - "id": "pFe9TS-KsUxb", - "colab_type": "code", - "colab": {} + "id": "pFe9TS-KsUxb" }, "source": [ "%%shell\n", - "python inference.py " + "python inference.py --model_path '/content/drive/MyDrive/Colab Notebooks/models/best-model_epoch-204_mae-0.0505_loss-0.1370.pth' --imgs_folder '/content/Pyramid-SD_PyTorch/data/DUTS/DUTS-TE'" ], "execution_count": null, "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "0jTOppHl7mVA" + }, + "source": [ + "## Resource Management\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "jc48cqcHuBv_", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 238 + }, + "outputId": "723997bc-409e-4ed5-abef-e8639738e5cd" + }, + "source": [ + "import resource\n", + "memMb=resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1024.0/1024.0\n", + "print (\" %5.1f MByte\" % (memMb))\n", + "\n", + "import torch\n", + "model1 = model.load_state_dict(torch.load('full.pth'))\n", + "print(model1)\n" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "text": [ + " 4.4 MByte\n" + ], + "name": "stdout" + }, + { + "output_type": "error", + "ename": "AttributeError", + "evalue": "ignored", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mmodel1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mload_state_dict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mload\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'full.pth'\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 7\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mAttributeError\u001b[0m: '_IncompatibleKeys' object has no attribute 'load_state_dict'" + ] + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "xGlo_AsH-f06", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 301 + }, + "outputId": "cfdd087b-f274-4f98-960b-fa33134ceef9" + }, + "source": [ + "import torch\n", + "import torchvision.models as models\n", + "import torch.autograd.profiler as profiler\n", + "\n", + "model = models.resnet18()\n", + "inputs = torch.randn(5, 3, 224, 224)\n", + "with profiler.profile(profile_memory=True, record_shapes=True) as prof:\n", + " model(inputs)\n", + "\n", + "# NOTE: some columns were removed for brevity\n", + "print(prof.key_averages().table(sort_by=\"self_cpu_memory_usage\", row_limit=10))\n", + "# --------------------------- --------------- --------------- ---------------\n", + "# Name CPU Mem Self CPU Mem Number of Calls\n", + "# --------------------------- --------------- --------------- ---------------\n", + "# empty 94.79 Mb 94.79 Mb 123\n", + "# resize_ 11.48 Mb 11.48 Mb 2\n", + "# addmm 19.53 Kb 19.53 Kb 1\n", + "# empty_strided 4 b 4 b 1\n", + "# conv2d 47.37 Mb 0 b 20\n", + "# --------------------------- --------------- --------------- ---------------" + ], + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "text": [ + "--------------------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- \n", + "Name Self CPU total % Self CPU total CPU total % CPU total CPU time avg CPU Mem Self CPU Mem CUDA Mem Self CUDA Mem Number of Calls \n", + "--------------------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- \n", + "empty 0.10% 510.341us 0.10% 510.341us 4.149us 94.79 Mb 94.79 Mb 0 b 0 b 123 \n", + "resize_ 0.00% 12.088us 0.00% 12.088us 6.044us 11.48 Mb 11.48 Mb 0 b 0 b 2 \n", + "addmm 1.08% 5.346ms 1.08% 5.351ms 5.351ms 19.53 Kb 19.53 Kb 0 b 0 b 1 \n", + "empty_strided 0.00% 5.885us 0.00% 5.885us 5.885us 4 b 4 b 0 b 0 b 1 \n", + "conv2d 0.05% 231.864us 65.12% 321.414ms 16.071ms 47.37 Mb 0 b 0 b 0 b 20 \n", + "convolution 0.02% 123.364us 65.07% 321.182ms 16.059ms 47.37 Mb 0 b 0 b 0 b 20 \n", + "_convolution 0.11% 539.993us 65.05% 321.059ms 16.053ms 47.37 Mb 0 b 0 b 0 b 20 \n", + "size 0.76% 3.754ms 0.76% 3.754ms 0.258us 0 b 0 b 0 b 0 b 14572 \n", + "contiguous 0.01% 29.759us 0.01% 29.759us 0.709us 0 b 0 b 0 b 0 b 42 \n", + "mkldnn_convolution 64.89% 320.247ms 64.93% 320.455ms 16.023ms 47.37 Mb 0 b 0 b 0 b 20 \n", + "--------------------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- \n", + "Self CPU time total: 493.558ms\n", + "\n" + ], + "name": "stdout" + } + ] } ] } \ No newline at end of file From 33a16d2b3843a10be4f62e8d29f5a6cab18ebf7f Mon Sep 17 00:00:00 2001 From: Parth Patel Date: Mon, 14 Dec 2020 17:08:41 +0100 Subject: [PATCH 8/9] Update pyramid_train.ipynb --- pyramid_train.ipynb | 108 -------------------------------------------- 1 file changed, 108 deletions(-) diff --git a/pyramid_train.ipynb b/pyramid_train.ipynb index bfec7d3..b831aee 100644 --- a/pyramid_train.ipynb +++ b/pyramid_train.ipynb @@ -135,114 +135,6 @@ ], "execution_count": null, "outputs": [] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "0jTOppHl7mVA" - }, - "source": [ - "## Resource Management\n" - ] - }, - { - "cell_type": "code", - "metadata": { - "id": "jc48cqcHuBv_", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 238 - }, - "outputId": "723997bc-409e-4ed5-abef-e8639738e5cd" - }, - "source": [ - "import resource\n", - "memMb=resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1024.0/1024.0\n", - "print (\" %5.1f MByte\" % (memMb))\n", - "\n", - "import torch\n", - "model1 = model.load_state_dict(torch.load('full.pth'))\n", - "print(model1)\n" - ], - "execution_count": null, - "outputs": [ - { - "output_type": "stream", - "text": [ - " 4.4 MByte\n" - ], - "name": "stdout" - }, - { - "output_type": "error", - "ename": "AttributeError", - "evalue": "ignored", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mmodel1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mload_state_dict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mload\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'full.pth'\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 7\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mAttributeError\u001b[0m: '_IncompatibleKeys' object has no attribute 'load_state_dict'" - ] - } - ] - }, - { - "cell_type": "code", - "metadata": { - "id": "xGlo_AsH-f06", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 301 - }, - "outputId": "cfdd087b-f274-4f98-960b-fa33134ceef9" - }, - "source": [ - "import torch\n", - "import torchvision.models as models\n", - "import torch.autograd.profiler as profiler\n", - "\n", - "model = models.resnet18()\n", - "inputs = torch.randn(5, 3, 224, 224)\n", - "with profiler.profile(profile_memory=True, record_shapes=True) as prof:\n", - " model(inputs)\n", - "\n", - "# NOTE: some columns were removed for brevity\n", - "print(prof.key_averages().table(sort_by=\"self_cpu_memory_usage\", row_limit=10))\n", - "# --------------------------- --------------- --------------- ---------------\n", - "# Name CPU Mem Self CPU Mem Number of Calls\n", - "# --------------------------- --------------- --------------- ---------------\n", - "# empty 94.79 Mb 94.79 Mb 123\n", - "# resize_ 11.48 Mb 11.48 Mb 2\n", - "# addmm 19.53 Kb 19.53 Kb 1\n", - "# empty_strided 4 b 4 b 1\n", - "# conv2d 47.37 Mb 0 b 20\n", - "# --------------------------- --------------- --------------- ---------------" - ], - "execution_count": null, - "outputs": [ - { - "output_type": "stream", - "text": [ - "--------------------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- \n", - "Name Self CPU total % Self CPU total CPU total % CPU total CPU time avg CPU Mem Self CPU Mem CUDA Mem Self CUDA Mem Number of Calls \n", - "--------------------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- \n", - "empty 0.10% 510.341us 0.10% 510.341us 4.149us 94.79 Mb 94.79 Mb 0 b 0 b 123 \n", - "resize_ 0.00% 12.088us 0.00% 12.088us 6.044us 11.48 Mb 11.48 Mb 0 b 0 b 2 \n", - "addmm 1.08% 5.346ms 1.08% 5.351ms 5.351ms 19.53 Kb 19.53 Kb 0 b 0 b 1 \n", - "empty_strided 0.00% 5.885us 0.00% 5.885us 5.885us 4 b 4 b 0 b 0 b 1 \n", - "conv2d 0.05% 231.864us 65.12% 321.414ms 16.071ms 47.37 Mb 0 b 0 b 0 b 20 \n", - "convolution 0.02% 123.364us 65.07% 321.182ms 16.059ms 47.37 Mb 0 b 0 b 0 b 20 \n", - "_convolution 0.11% 539.993us 65.05% 321.059ms 16.053ms 47.37 Mb 0 b 0 b 0 b 20 \n", - "size 0.76% 3.754ms 0.76% 3.754ms 0.258us 0 b 0 b 0 b 0 b 14572 \n", - "contiguous 0.01% 29.759us 0.01% 29.759us 0.709us 0 b 0 b 0 b 0 b 42 \n", - "mkldnn_convolution 64.89% 320.247ms 64.93% 320.455ms 16.023ms 47.37 Mb 0 b 0 b 0 b 20 \n", - "--------------------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- --------------- \n", - "Self CPU time total: 493.558ms\n", - "\n" - ], - "name": "stdout" - } - ] } ] } \ No newline at end of file From 2c9578dae8e801a3a1e96c169b487217142aaa8c Mon Sep 17 00:00:00 2001 From: Parth Patel Date: Mon, 14 Dec 2020 17:16:52 +0100 Subject: [PATCH 9/9] Colab Notebook --- pyramid_train.ipynb => pyramid_train&infer.ipynb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) rename pyramid_train.ipynb => pyramid_train&infer.ipynb (92%) diff --git a/pyramid_train.ipynb b/pyramid_train&infer.ipynb similarity index 92% rename from pyramid_train.ipynb rename to pyramid_train&infer.ipynb index b831aee..7f5d2f7 100644 --- a/pyramid_train.ipynb +++ b/pyramid_train&infer.ipynb @@ -88,6 +88,13 @@ } ] }, + { + "source": [ + "Download the DUTS Dataset " + ], + "cell_type": "markdown", + "metadata": {} + }, { "cell_type": "code", "metadata": { @@ -124,6 +131,13 @@ "execution_count": null, "outputs": [] }, + { + "source": [ + "Download pre-trained model. Link in the README.md" + ], + "cell_type": "markdown", + "metadata": {} + }, { "cell_type": "code", "metadata": {