run_lpo.py

컴퓨터비전/영상처리 2015. 9. 29. 21:02
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
"""
Make sure you have LPO_DIR/src in your python path
"""
 
import lpo
from lpo import *
from util import *
import cv2
import numpy as np
import os
from pylab import *
 
# ------------- filenames -----------------
dataset = "50Salads"
filename = "rgb-01-1.avi"
# ------------- Folder names -----------------
# url_files = os.path.expanduser("~/Desktop/tmp2/".format(dataset))
url_files = os.path.expanduser("~/Data/{}/raw/rgb/".format(dataset))
url_img_save = os.path.expanduser("~/Data/{}/viz/lpo/".format(dataset))
url_bbox_save = os.path.expanduser("~/Data/{}/features/lpo/S1_Cheese_C1/".format(dataset))
# I can only get the library to read images from disk (instead of from video stream)
# So save video file to temporary image and then load...
tmp_filename = os.path.expanduser("~/Desktop/tmp.png")
# ------------- User params -----------------
save_file = [False, True][0]
n_superpixels = 200
rez = (854480)
# I threshold out boxes that are too big or too small
min_box_len = 50
max_box_len = 250
# This list is all available overlap scores.
overlap_score = [.01, .02, .03, .05, .1, .2][-1]
# ---------------------------------------------
 
# Load the ensemble
prop = proposals.LPO()
dir_lpo = os.path.dirname(lpo.__file__).strip("src")
prop.load(dir_lpo+"/models/lpo_VOC_{}.dat".format(overlap_score))
detector = getDetector('mssf')
 
# Check that the save folder exists
if not os.path.exists(url_img_save):
    os.mkdir(url_img_save)
 
vid = cv2.VideoCapture(os.path.expanduser(url_files+filename))
 
# Evaluate on the test set
i=0
while 1:
    ret, im_cv = vid.read()
    if not ret:
        break
    # im_cv = cv2.resize(im, rez)
 
    cv2.imwrite(tmp_filename, im_cv)
    im = imgproc.imread(tmp_filename)
 
    # Extract object proposals from oversegmented regions
    over_segs = segmentation.generateGeodesicKMeans( detector, [im], n_superpixels)
    props = prop.propose(over_segs)[0]
    segs = props[0].s
 
    # Display bounding boxes
    boxes = props[0].toBoxes()
    for b in boxes:
        x1,y1,x2,y2 = b
        if (min_box_len < (x2 - x1) < max_box_len) and \
            (min_box_len < (y2 - y1) < max_box_len):
            cv2.rectangle(im_cv,(x1,y1),(x2,y2),(0,255,0),1)
    cv2.imshow("im", im_cv)
    cv2.waitKey(30)
 
    # # Overlay superpixels onto image to create heatmap
    # im_ = np.zeros_like(im_cv[:,:,2])*1.
    # for o in props[0].p:
    #     for spx in np.nonzero(o)[0]:
    #         im_[segs==spx] += 1
    #
    #     # im_ += (segs == np.nonzero(o)[0][:,None,None]).sum(0)
    #
    # cv2.imshow("heatmap", im_/im_.max())
    # cv2.waitKey(30)
 
    # Save image and bounding box/segmentation to file
    if save_file:
        base_filename = str(i*framerate)+".jpg"
        cv2.imwrite(url_img_save+base_filename, im_cv)
        saveProposalsHDF5( props, url_bbox_save+base_filename+'.hf5', True, True )
 
    i+=1
cs


Deep Learning 두번째 세미나

패턴인식 & 기계학습 2015. 9. 29. 00:16

'패턴인식 & 기계학습' 카테고리의 다른 글

Automatically image Description(Auto Caption)  (0) 2015.10.06
Jaccard similarity 계산  (0) 2015.10.02
딥러닝 framework Theano 설치  (0) 2015.09.21
에이다부스트(adaboost)  (0) 2015.02.27
k-means clustering  (0) 2015.02.27

딥러닝 framework Theano 설치

패턴인식 & 기계학습 2015. 9. 21. 21:35

reference : http://deeplearning.net/software/theano/install_ubuntu.html#install-ubuntu


For Ubuntu 11.10 through 14.04:

sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libopenblas-dev git
sudo pip install Theano



If you would like, instead, to install the bleeding edge Theano (from github) such that you can edit and contribute to Theano, replace the pip install Theano command with:

git clone git://github.com/Theano/Theano.git
cd Theano
python setup.py develop --user
cd ..


Updating Theano

If you followed these installation instructions, you can execute this command to update only Theano:

sudo pip install --upgrade --no-deps theano

If you want to also installed NumPy/SciPy with pip instead of the system package, you can run this:

sudo pip install --upgrade theano


'패턴인식 & 기계학습' 카테고리의 다른 글

Jaccard similarity 계산  (0) 2015.10.02
Deep Learning 두번째 세미나  (0) 2015.09.29
에이다부스트(adaboost)  (0) 2015.02.27
k-means clustering  (0) 2015.02.27
딥러닝 Deep Learning  (0) 2015.02.27