From 1c91225d23ef157f7b7c38fd6d14205384e6d17c Mon Sep 17 00:00:00 2001 From: Tim Esler Date: Mon, 9 Sep 2019 18:52:31 -0700 Subject: [PATCH] Add fine-tuning code --- .gitignore | 3 +- examples/{train.ipynb => finetune.ipynb} | 49 ++++++------------------ setup.py | 2 +- 3 files changed, 15 insertions(+), 39 deletions(-) rename examples/{train.ipynb => finetune.ipynb} (88%) diff --git a/.gitignore b/.gitignore index df4df846..e77d25dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__ .vscode -.ipynb_checkpoints \ No newline at end of file +.ipynb_checkpoints +runs diff --git a/examples/train.ipynb b/examples/finetune.ipynb similarity index 88% rename from examples/train.ipynb rename to examples/finetune.ipynb index c3d09486..b03d18e3 100644 --- a/examples/train.ipynb +++ b/examples/finetune.ipynb @@ -41,8 +41,8 @@ "metadata": {}, "outputs": [], "source": [ - "data_dir = '/home/tim/data/vggface2/train'\n", - "batch_size = 64\n", + "data_dir = '/mnt/windows/Users/times/Data/vggface2/test'\n", + "batch_size = 32\n", "epochs = 15" ] }, @@ -55,7 +55,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -84,7 +84,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -110,26 +110,17 @@ "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Images processed: 3141890 of 3141890 | fps: 129" - ] - } - ], + "outputs": [], "source": [ "dataset = datasets.ImageFolder(data_dir)\n", "dataset.idx_to_class = {i:c for c, i in dataset.class_to_idx.items()}\n", "loader = DataLoader(dataset, collate_fn=lambda x: x[0], num_workers=mp.cpu_count(), shuffle=False)\n", "\n", - "timer = training.BatchTimer(per_sample=False)\n", "for i, (x, y) in enumerate(loader):\n", - " print(f'\\rImages processed: {i + 1:8d} of {len(loader):8d} | fps: {timer():.0f}', end='')\n", + " print(f'\\rImages processed: {i + 1:8d} of {len(loader):8d}', end='')\n", " save_dir = os.path.join(data_dir + '_cropped', dataset.idx_to_class[y])\n", " os.makedirs(save_dir, exist_ok=True)\n", - " filename = f'{len(os.listdir(save_dir)):05n}.png'\n", + " filename = f'{len(os.listdir(save_dir)):05n}.jpg'\n", " mtcnn(x, save_path=os.path.join(save_dir, filename))\n", " \n", "del mtcnn" @@ -148,7 +139,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -168,7 +159,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -209,7 +200,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -231,26 +222,10 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n", - "Initial\n", - "----------\n", - "Eval | 9912/9912 | loss: 8.6591 | fps: 1143.2909 | acc: 0.0009 \n", - "\n", - "Epoch 1/15\n", - "----------\n", - "Train | 12100/39647| loss: 5.4847 | fps: 320.4110 | acc: 0.3272 " - ] - } - ], + "outputs": [], "source": [ "writer = SummaryWriter()\n", - "writer.iterations = 0\n", + "writer.iteration, writer.interval = 0, 10\n", "\n", "print(f'\\n\\nInitial')\n", "print('-' * 10)\n", diff --git a/setup.py b/setup.py index f6f796d8..6d3f7f1a 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ import setuptools, os PACKAGE_NAME = 'facenet-pytorch' -VERSION = '0.2.1' +VERSION = '0.2.2' AUTHOR = 'Tim Esler' EMAIL = 'tim.esler@gmail.com' DESCRIPTION = 'Pretrained Pytorch face detection and recognition models'