forked from ethanhe42/Ultrasound-Nerve-Segmentation
/
solve_polyp.py
61 lines (50 loc) · 1.6 KB
/
solve_polyp.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
#-.-encoding=utf-8-.-``
# Yihui He, https://yihui-he.github.io
import sys
import pandas as pd
sys.path.append("/home/yihuihe/Ultrasound-Nerve-Segmentation")
sys.path.insert(0, "/home/yihuihe/miscellaneous/caffe/python")
print sys.path
import caffe
print caffe.__file__
import numpy as np
import cv2
from utils import NetHelper, CaffeSolver
# import cfgs
import cfgs_polyp as cfgs
#import score
#import surgery
import os
import matplotlib.pyplot as plt
# gen solver prototxt
# solver=CaffeSolver(debug=cfgs.debug)
# solver.sp=cfgs.sp.copy()
# solver.write(cfgs.solver_pt)
debug=True
weights = cfgs.init
# init
caffe.set_device(2)
caffe.set_mode_gpu()
# caffe.set_mode_cpu()
solver = caffe.SGDSolver(cfgs.solver_pt)
if weights is not None:
solver.net.copy_from(weights)
for iter in range(500*2000):
if debug:
if iter % 100 == 0 and iter !=0:
nethelper=NetHelper(solver.net)
# nethelper.hist('data')
# nethelper.hist('label')
nethelper.hist('prob', filters=2,attr="blob")
if False:
for i in range(nethelper.net.blobs['data1'].data.shape[0]):
plt.subplot(221)
plt.imshow(nethelper.net.blobs['data1'].data[i,0])
plt.subplot(222)
plt.imshow(nethelper.net.blobs['prob'].data[i,0])
plt.subplot(223)
plt.imshow(nethelper.net.blobs['label'].data[i,0])
plt.show()
# TODO: label has float
# nethelper.value_counts('label')
solver.step(1)