-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestSegmenetation.py
More file actions
109 lines (84 loc) · 2.45 KB
/
Copy pathtestSegmenetation.py
File metadata and controls
109 lines (84 loc) · 2.45 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# import the necessary packages
from __future__ import division
from keras.preprocessing.image import img_to_array
from keras.models import load_model
from keras.optimizers import Adam
import numpy as np
import argparse
import imutils
from imutils import paths
import cv2
import os
import math
from sklearn import metrics
import h5py
from sklearn.metrics import confusion_matrix
from sklearn.metrics import f1_score
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
ap = argparse.ArgumentParser()
ap.add_argument("-d", "--dataset", required=True,
help="path to input dataset")
ap.add_argument("-m", "--model", required=True,
help="path to output model")
args = vars(ap.parse_args())
# initialize the number of epochs to train for, initial learning rate,
# and batch size
EPOCHS = 50
INIT_LR = 1e-4
BS = 50
import os
os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID";
# The GPU id to use, usually either "0" or "1";
os.environ["CUDA_VISIBLE_DEVICES"]="1";
# initialize the data and labels
hilbert = []
labels = []
print(args["dataset"])
# Envolope Directory loading
print("[INFO] loading raw envolopes in...")
fileCount = 0
for filename in os.listdir(args["dataset"]):
if filename.endswith(".csv"):
print(fileCount)
fileCount += 1
#Importing the raw csv data
rawCSVHilbert = np.loadtxt(args["dataset"]+'/'+filename)
print(rawCSVHilbert.size)
if rawCSVHilbert.size == 4000:
hilbert.append(rawCSVHilbert)
data = np.array(hilbert)
print("Data shape:", data.shape)
# split into input (X) and output (Y) variables
X = data
#Reshaping the data
X = np.expand_dims(X, axis=2) # reshape (training_size, 88200) to (569, 30, 1)
print(X.shape)
# fix random seed for reproducibility
seed = 7
np.random.seed(seed)
# Intialize TP, FN, TN, FP
TP = 0
FN = 0
TN = 0
FP = 0
#Start probabilities
#fileNum start and stop indicies
fileStarts =[]
fileEnds =[]
segProbs= []
# load the trained convolutional neural network
print("[INFO] loading network...")
model = load_model(args["model"])
#model = DenseNet(reduction=0.5, classes=2, weights_path=weights_path)
opt = Adam(lr=INIT_LR, decay=INIT_LR / EPOCHS)
model.compile(loss="binary_crossentropy", optimizer=opt,
metrics=["accuracy"])
for vectorCount in range(0,X.shape[0]):
testData = X[vectorCount,:,:]
testData = testData.reshape(1,4000,1)
print("Test data shape", testData.shape)
segmentationProbs = model.predict(testData)[0]
segProbs.append(segmentationProbs)
np.save('segProbsTest', segProbs)