Skip to content
This repository has been archived by the owner on Jan 4, 2021. It is now read-only.

Commit

Permalink
Train local attention model
Browse files Browse the repository at this point in the history
  • Loading branch information
dattran2346 committed Feb 3, 2019
1 parent 2662f35 commit 4737199
Show file tree
Hide file tree
Showing 23 changed files with 1,178 additions and 2,272 deletions.
242 changes: 242 additions & 0 deletions src/Heatmap.ipynb

Large diffs are not rendered by default.

77 changes: 74 additions & 3 deletions src/CAM.ipynb → src/Old CAM.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,69 @@
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"%reload_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Generate CAM (Class Activation Map)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"import pandas as pd\n",
"from constant import CSV_DIR, CLASS_NAMES\n",
"import numpy as np"
"import numpy as np\n",
"\n",
"from fastai.conv_learner import *\n",
"# import pixiedust\n",
"from matplotlib.patches import Rectangle\n",
"from datetime import datetime\n",
"import pandas as pd\n",
"\n",
"import torch\n",
"from layers import *\n",
"from constant import CLASS_NAMES\n",
"from transform import chest_xray_transfrom\n",
"from metrics import *\n",
"import pretrainedmodels\n",
"from recorder import TrainingRecoder\n",
"import pretrainedmodels\n",
"from dataset import ChestXray14Dataset\n",
"from model_data import ModelData\n",
"from chexnet import ChexNet"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"PATH = Path('/home/dattran/data/xray-thesis/chestX-ray14')\n",
"IMAGE_DN = 'images'\n",
"IMAGE_NAME = '00007551_000.png'\n",
"sz = 224\n",
"\n",
" \n",
"densenet = pretrainedmodels.__dict__['densenet121']()\n",
"tfms = chest_xray_transfrom(densenet, sz, .875)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -32,6 +84,25 @@
" plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"class FeatureHook:\n",
" features = None\n",
" \n",
" def __init__(self, m):\n",
" self.hook = m.register_forward_hook(self.hook_fn)\n",
" \n",
" def hook_fn(self, module, input, output):\n",
" self.features = output\n",
" \n",
" def remove(self):\n",
" self.hook.remove()"
]
},
{
"cell_type": "code",
"execution_count": 3,
Expand Down Expand Up @@ -1097,7 +1168,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.6"
"version": "3.7.0"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 4737199

Please sign in to comment.