forked from RyanDsilva/alzheimers-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalzheimers_pred.py
59 lines (37 loc) · 1.33 KB
/
alzheimers_pred.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
"""Alzheimers_Pred.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1M9TrktFEwnH5BZgmEFVzjhncLqqtUzeo
"""
import warnings
warnings.filterwarnings('ignore')
"""# Alzherimers Detection using MRI Scans"""
from google.colab import drive
drive.mount('/content/drive')
!tar -xf "/content/drive/My Drive/AlzModel/dataset.tar.xz"
PATH = 'dataset/'
from fastai import *
from fastai.vision import *
from fastai.metrics import accuracy
tfms = get_transforms()
data = ImageDataBunch.from_folder(PATH, valid='validation', ds_tfms=tfms, bs=64, num_workers=4).normalize(imagenet_stats)
data.classes
model = cnn_learner(data, models.densenet201, metrics=accuracy, pretrained=True)
model.fit_one_cycle(5)
model.save('alzheimersv1-initial')
model.unfreeze()
model.lr_find()
model.recorder.plot(suggestion=True)
model.fit_one_cycle(25, max_lr=6.31e-07)
interp = ClassificationInterpretation.from_learner(model)
interp.plot_confusion_matrix()
interp.plot_top_losses(4, figsize=(8,8))
model.save('alzheimers')
model.export('/content/drive/My Drive/AlzModel/alzDensenet201.pt')
DRIVE_PATH = '/content/drive/My Drive/AlzModel/'
predictor = load_learner(DRIVE_PATH,'alzDensenet201.pt')
img = open_image(DRIVE_PATH+'YAL0001.jpg')
img
pred = predictor.predict(img)
pred[0]