-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtesting_pipeline.py
67 lines (55 loc) · 2.24 KB
/
testing_pipeline.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
60
61
62
63
64
65
66
67
from __future__ import division,print_function, absolute_import
import numpy as np
import tensorflow as tf
import skimage
from skimage import io
import tflearn
from tflearn.data_utils import shuffle, to_categorical
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.estimator import regression
from tflearn.data_preprocessing import ImagePreprocessing
from tflearn.data_augmentation import ImageAugmentation
# Real-time data preprocessing
img_prep = ImagePreprocessing()
img_prep.add_featurewise_zero_center()
img_prep.add_featurewise_stdnorm()
# Real-time data augmentation
img_aug = ImageAugmentation()
img_aug.add_random_flip_leftright()
img_aug.add_random_rotation(max_angle=25.)
# Convolutional network building
network = input_data(shape=[None, 256, 256, 3],
data_preprocessing=img_prep, data_augmentation=img_aug)
network = conv_2d(network, 32, 3, activation='relu')
network = max_pool_2d(network, 2)
network = conv_2d(network, 64, 3, activation='relu')
network = conv_2d(network, 64, 3, activation='relu')
network = max_pool_2d(network, 2)
network = fully_connected(network, 512, activation='relu')
network = dropout(network, 0.5)
network = fully_connected(network, 4, activation='softmax')
network = regression(network, optimizer='adam',
loss='categorical_crossentropy',
learning_rate=0.001)
# Train using classifier
model = tflearn.DNN(network, tensorboard_verbose=3)
model.load("models/run1.tflearn")
DATAPATH = "/Users/surajnair/Downloads/wfgO4XffLJBKS4ZlxQorLE05Xo0MmwjV/"
DATAPATH3 = "/Users/surajnair/Downloads/"
with open(DATAPATH + "test.txt") as f:
dt = f.readlines()
for fl in dt:
try:
fl_sp = fl.split()
# print fl_sp
name = fl_sp[0]
patient = int(fl_sp[1][1:-1])
node = int(fl_sp[2][1:-1])
if patient >= 100:
# print(np.array([io.imread(DATAPATH3 + name)]))
y = model.predict(np.array([io.imread(DATAPATH3 + name)]).astype("float"))
f = open('predictions/run1raw.csv', 'a')
f.write(str(patient)+"," + str(node) + "," + str(np.argmax(y[0])) + "\n")
except IndexError:
continue