Skip to content

Commit

Permalink
change to fp16
Browse files Browse the repository at this point in the history
  • Loading branch information
kentaroy47 committed Jan 30, 2020
1 parent 19789f4 commit 49c4edb
Show file tree
Hide file tree
Showing 8 changed files with 3,336 additions and 2,645 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Now training models.. Plz wait.
|*backbone* |*resolution*|*VOCmAP* |*COCOmAP*|*Inference[ms]*|*model*|
|:------: |:------------:|:----------:|:-------:|:-------------:|:-----:|
|EfficientnetB0(wo/BiFPN)|512 |77.0 |TBD | | |
|EfficientnetB0(w/BiFPN) |512 |79.0 |TBD | | |
|EfficientnetB0(w/BiFPN) |512 |77.2 |TBD | | |
|EfficientnetB2(wo/BiFPN)|768 |TBD |TBD | | |
|EfficientnetB2(w/BiFPN) |768 |TBD |TBD | | |
|EfficientnetB4(wo/BiFPN)|1024 |TBD |TBD | | |
Expand Down
238 changes: 207 additions & 31 deletions eval.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
"train_img_list, train_anno_list, val_img_list, val_anno_list = make_datapath_list(vocpath)\n",
"\n",
"model=\"efficientdet\"\n",
"backbone = \"efficientnet-b2\"\n",
"scale = 2"
"backbone = \"efficientnet-b0\"\n",
"scale = 1"
]
},
{
Expand Down Expand Up @@ -148,18 +148,18 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 11,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'DATASET' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-1-edf285b2353f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mDATASET\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"COCO\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mnum_class\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m21\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mnum_class\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m81\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'DATASET' is not defined"
"name": "stdout",
"output_type": "stream",
"text": [
"Loaded pretrained weights for efficientnet-b0\n",
"320\n",
"use BiFPN\n",
"loaded the trained weights\n",
"using: cuda:0\n"
]
}
],
Expand Down Expand Up @@ -212,7 +212,7 @@
" map_location={'cuda:0': 'cpu'})\n",
"else:\n",
" net = EfficientDet(phase=\"inference\", cfg=ssd_cfg, verbose=False, backbone=backbone, useBiFPN=True)\n",
" net_weights = torch.load('./weights/VOC_efficientnet-b2_600_BiFPN_100.pth',\n",
" net_weights = torch.load('./weights/VOC_efficientnet-b0_300_BiFPN_200.pth',\n",
" map_location={'cuda:0': 'cpu'})\n",
"\n",
"net.load_state_dict(net_weights)\n",
Expand All @@ -227,7 +227,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -243,9 +243,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cuda:0\n"
]
}
],
"source": [
"from utils.ssd_predict_show import SSDPredictShow\n",
"ssd = SSDPredictShow(eval_categories=voc_classes, net=net, device=device, image_size=input_size)"
Expand All @@ -260,7 +268,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {
"scrolled": true
},
Expand All @@ -271,18 +279,65 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"['../VOCdevkit/VOC2007/JPEGImages/000001.jpg',\n",
" '../VOCdevkit/VOC2007/JPEGImages/000002.jpg',\n",
" '../VOCdevkit/VOC2007/JPEGImages/000003.jpg',\n",
" '../VOCdevkit/VOC2007/JPEGImages/000004.jpg',\n",
" '../VOCdevkit/VOC2007/JPEGImages/000006.jpg',\n",
" '../VOCdevkit/VOC2007/JPEGImages/000008.jpg',\n",
" '../VOCdevkit/VOC2007/JPEGImages/000010.jpg',\n",
" '../VOCdevkit/VOC2007/JPEGImages/000011.jpg',\n",
" '../VOCdevkit/VOC2007/JPEGImages/000013.jpg',\n",
" '../VOCdevkit/VOC2007/JPEGImages/000014.jpg']"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"val_img_list[0:10]"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"iter: 0\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/nn/functional.py:2457: UserWarning: nn.functional.upsample is deprecated. Use nn.functional.interpolate instead.\n",
" warnings.warn(\"nn.functional.upsample is deprecated. Use nn.functional.interpolate instead.\")\n",
"/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/nn/functional.py:2539: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details.\n",
" \"See the documentation of nn.Upsample for details.\".format(mode))\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"iter: 1000\n",
"iter: 3000\n",
"iter: 4000\n"
]
}
],
"source": [
"for i, imp in enumerate(val_img_list):\n",
" detections, pre_dict_label_index = ssd.ssd_predict2(imp, data_confidence_level=0.05)\n",
Expand All @@ -302,9 +357,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[array([], shape=(0, 5), dtype=float64),\n",
" array([], shape=(0, 5), dtype=float64),\n",
" array([], shape=(0, 5), dtype=float64),\n",
" array([], shape=(0, 5), dtype=float64),\n",
" array([], shape=(0, 5), dtype=float64),\n",
" array([], shape=(0, 5), dtype=float64),\n",
" array([], shape=(0, 5), dtype=float64),\n",
" [array([ 0.7535214, 137.66829 , 84.52406 , 326.27124 , 302.4893 ],\n",
" dtype=float32)],\n",
" array([], shape=(0, 5), dtype=float64),\n",
" array([], shape=(0, 5), dtype=float64)]"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"all_boxes[7][0:10]"
]
Expand All @@ -318,7 +394,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -476,7 +552,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -497,7 +573,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -585,7 +661,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -594,9 +670,49 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Writing aeroplane VOC results file\n",
"Writing bicycle VOC results file\n",
"Writing bird VOC results file\n",
"Writing boat VOC results file\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/ipykernel_launcher.py:21: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Writing bottle VOC results file\n",
"Writing bus VOC results file\n",
"Writing car VOC results file\n",
"Writing cat VOC results file\n",
"Writing chair VOC results file\n",
"Writing cow VOC results file\n",
"Writing diningtable VOC results file\n",
"Writing dog VOC results file\n",
"Writing horse VOC results file\n",
"Writing motorbike VOC results file\n",
"Writing person VOC results file\n",
"Writing pottedplant VOC results file\n",
"Writing sheep VOC results file\n",
"Writing sofa VOC results file\n",
"Writing train VOC results file\n",
"Writing tvmonitor VOC results file\n"
]
}
],
"source": [
"write_voc_results_file(pascal_classes, all_boxes, val_img_list)"
]
Expand All @@ -610,7 +726,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -663,9 +779,69 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"VOC07 metric? No\n",
"AP for aeroplane = 0.8093\n",
"AP for bicycle = 0.8631\n",
"AP for bird = 0.7861\n",
"AP for boat = 0.7077\n",
"AP for bottle = 0.4031\n",
"AP for bus = 0.8470\n",
"AP for car = 0.8519\n",
"AP for cat = 0.9062\n",
"AP for chair = 0.5554\n",
"AP for cow = 0.8457\n",
"AP for diningtable = 0.7194\n",
"AP for dog = 0.9009\n",
"AP for horse = 0.8980\n",
"AP for motorbike = 0.8618\n",
"AP for person = 0.7593\n",
"AP for pottedplant = 0.4591\n",
"AP for sheep = 0.8089\n",
"AP for sofa = 0.8020\n",
"AP for train = 0.8793\n",
"AP for tvmonitor = 0.7795\n",
"Mean AP = 0.7722\n",
"~~~~~~~~\n",
"Results:\n",
"0.809\n",
"0.863\n",
"0.786\n",
"0.708\n",
"0.403\n",
"0.847\n",
"0.852\n",
"0.906\n",
"0.555\n",
"0.846\n",
"0.719\n",
"0.901\n",
"0.898\n",
"0.862\n",
"0.759\n",
"0.459\n",
"0.809\n",
"0.802\n",
"0.879\n",
"0.779\n",
"0.772\n",
"~~~~~~~~\n",
"\n",
"--------------------------------------------------------------\n",
"Results computed with the **unofficial** Python eval code.\n",
"Results should be very close to the official MATLAB eval code.\n",
"Recompute with `./tools/reval.py --matlab ...` for your paper.\n",
"-- Thanks, The Management\n",
"--------------------------------------------------------------\n"
]
}
],
"source": [
"# evaluate detections\n",
"python_eval()"
Expand Down
Loading

0 comments on commit 49c4edb

Please sign in to comment.