Skip to content

Commit

Permalink
Add fine-tuning code
Browse files Browse the repository at this point in the history
  • Loading branch information
timesler committed Sep 10, 2019
1 parent 2939dfc commit 1c91225
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__
.vscode
.ipynb_checkpoints
.ipynb_checkpoints
runs
49 changes: 12 additions & 37 deletions examples/train.ipynb → examples/finetune.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
Expand All @@ -55,7 +55,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -84,7 +84,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -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"
Expand All @@ -148,7 +139,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -168,7 +159,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -209,7 +200,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import setuptools, os

PACKAGE_NAME = 'facenet-pytorch'
VERSION = '0.2.1'
VERSION = '0.2.2'
AUTHOR = 'Tim Esler'
EMAIL = '[email protected]'
DESCRIPTION = 'Pretrained Pytorch face detection and recognition models'
Expand Down

0 comments on commit 1c91225

Please sign in to comment.