-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
2,250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
FROM ubuntu:16.04 | ||
|
||
LABEL maintainer="Toni Kunic <[email protected]>" | ||
|
||
################################################################################ | ||
### Apt and pip dependencies | ||
|
||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
build-essential \ | ||
python-pip \ | ||
python-setuptools \ | ||
python-matplotlib \ | ||
python-dev \ | ||
python-tk \ | ||
libxml2-dev \ | ||
libxslt-dev \ | ||
git && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
COPY ./smiler_tools /tmp/smiler_tools | ||
RUN pip install /tmp/smiler_tools | ||
|
||
################################################################################ | ||
### Run command on container start. | ||
|
||
VOLUME ["/opt/model"] | ||
VOLUME ["/opt/input_vol"] | ||
VOLUME ["/opt/output_vol"] | ||
|
||
WORKDIR /opt/model | ||
|
||
CMD ["/bin/bash"] | ||
|
||
################################################################################ | ||
### Set up liblinear and sthor. | ||
|
||
RUN pip install --upgrade pip setuptools | ||
RUN pip install setuptools cython numpy scipy numexpr scikit-image liblinear hyperopt | ||
|
||
RUN mkdir /opt/dependencies && \ | ||
cd /opt/dependencies && \ | ||
git clone https://github.com/tkunic/sthor.git && \ | ||
cd /opt/dependencies/sthor/sthor/operation && \ | ||
make && \ | ||
pip install /opt/dependencies/sthor | ||
|
||
RUN cd /opt/dependencies && \ | ||
git clone https://github.com/cjlin1/liblinear && \ | ||
cd liblinear && \ | ||
git checkout tags/v201 && \ | ||
make && \ | ||
cd python && \ | ||
make | ||
|
||
ENV PYTHONPATH "${PYTONPATH}:/opt/dependencies/liblinear/python:/opt/dependencies/sthor/:/opt/dependencies/sthor/build/lib.linux-x86_64-2.7/sthor/sthor/:/opt/dependencies/sthor/build/lib.linux-x86_64-2.7/sthor/sthor/resample/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Packages | ||
*.egg | ||
*.egg-info | ||
dist | ||
build | ||
eggs | ||
parts | ||
bin | ||
var | ||
sdist | ||
develop-eggs | ||
.installed.cfg | ||
lib | ||
lib64 | ||
|
||
# Installer logs | ||
pip-log.txt | ||
|
||
# Unit test / coverage reports | ||
.coverage | ||
.tox | ||
nosetests.xml | ||
|
||
# Translations | ||
*.mo | ||
|
||
# Mr Developer | ||
.mr.developer.cfg | ||
.project | ||
.pydevproject | ||
|
||
# Model files | ||
svm-slm | ||
svm-slm-cntr | ||
whiten-slm | ||
whiten-slm-cntr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 coxlab | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
eDN-saliency | ||
============ | ||
This repository contains reference code for computing Ensembles of Deep Networks (eDN) saliency maps based on the CVPR'2014 paper "Large-Scale Optimization of Hierarchical Features for Saliency Prediction in Natural Images". | ||
|
||
Usage | ||
----- | ||
|
||
``` | ||
./eDNsaliency [--opts] <image> <output_saliency_map> | ||
Options: | ||
-h, --help show this help message and exit | ||
--descs DESCPATH path to eDN model(s) (default: ./slmBestDescrCombi.pkl) | ||
--svm SVMPATH path to SVM file (default: ./svm-slm-cntr) | ||
--white WHITEPATH path to whitening parameters (default: ./whiten-slm-cntr) | ||
--fixMap FIXMAP fixation map / empirical saliency map, if available | ||
--histeq histogram equalization with given empirical saliency map | ||
(default: False); requires empirical saliency map | ||
--auc computes AUC for given fixation map; requires fixation map | ||
--no-blur disable the default smoothing of the final map | ||
``` | ||
|
||
Input format: | ||
+ fixation map: black image with fixated pixels (one per fixation) set to 255 (see ./img_fixPts.jpg) | ||
+ empirical saliency map: superposition of Gaussians centered at fixations (see ./img_fixMap.jpg) | ||
|
||
These images should have the same size as the input image. | ||
|
||
Examples | ||
-------- | ||
|
||
``` | ||
./eDNsaliency img.jpg salMap.jpg | ||
Computes raw (non-histogram-equalized) saliency map (in salMap.jpg) for given image | ||
./eDNsaliency --histeq --fixMap img_fixMap.jpg img.jpg salMap-histeq.jpg | ||
Computes histogram-equalized saliency map with given empirical saliency map (img_fixMap.jpg) | ||
./eDNsaliency --auc --fixMap img_fixPts.jpg img.jpg salMap.jpg | ||
Computes Area Under the Curve (AUC) for fixation map (img_fixPts.jpg) | ||
./eDNsaliency --svm ./svm-slm --white ./whiten-slm img.jpg salMap-noCntr.jpg | ||
Computes non-centered saliency maps | ||
``` | ||
|
||
|
||
Requirements | ||
------------ | ||
|
||
``` | ||
sthor | ||
liblinear | ||
``` | ||
|
||
|
||
Installation | ||
------------ | ||
|
||
(Tested under Ubuntu 14.04) | ||
|
||
1. Install dependencies | ||
``` | ||
sudo apt-get install python-matplotlib python-setuptools curl python-dev libxml2-dev libxslt-dev | ||
``` | ||
|
||
2. Install liblinear | ||
|
||
Download toolbox from http:https://www.csie.ntu.edu.tw/~cjlin/liblinear/ | ||
|
||
``` | ||
# extract the zip | ||
make | ||
cd python | ||
make | ||
``` | ||
|
||
3. Install sthor dependencies | ||
|
||
``` | ||
curl -O http:https://python-distribute.org/distribute_setup.py | ||
sudo python distribute_setup.py | ||
sudo easy_install pip | ||
sudo easy_install -U scikit-image | ||
sudo easy_install -U cython | ||
sudo easy_install -U numexpr | ||
sudo easy_install -U scipy | ||
``` | ||
|
||
For speedup, numpy and numexpr should be built against e.g. Intel MKL libraries. | ||
|
||
4. Install sthor | ||
|
||
``` | ||
git clone https://github.com/nsf-ri-ubicv/sthor.git | ||
cd sthor/sthor/operation | ||
sudo make | ||
cd ../.. | ||
python setup.py install | ||
``` | ||
add the sthor directory and the liblinear/python directory to your PYTHONPATH | ||
|
||
5. Test sthor installation | ||
|
||
``` | ||
python | ||
import sthor # should import without errors | ||
``` | ||
|
||
Precomputed Saliency Maps | ||
------------------------- | ||
|
||
We provide precomputed saliency maps for three standard benchmarks: | ||
+ MIT data set: MIT1003_eDN.zip | ||
+ Toronto data set: Toronto_eDN.zip | ||
+ NUSEF data set: NUSEF_eDN.zip | ||
|
||
|
||
Citing this Code | ||
---------------- | ||
|
||
If you use this code in your own work, please cite the following paper: | ||
|
||
Eleonora Vig, Michael Dorr, David Cox, "Large-Scale Optimization of Hierarchical Features for Saliency Prediction in Natural Images", IEEE Computer Vision and Pattern Recognition (CVPR), 2014. | ||
|
||
Link to the paper: http:https://coxlab.org/pdfs/cvpr2014_vig_saliency.pdf | ||
|
||
For questions and feedback please contact me at [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import numpy as np | ||
import scipy as sp | ||
from scipy import misc | ||
import time | ||
import logging | ||
|
||
from liblinearutil import predict | ||
|
||
from features import eDN_features, dist_to_cntr_features, whiten_features | ||
|
||
EDN_INSIZE = (512, 384) | ||
|
||
|
||
class EDNSaliencyModel(object): | ||
def __init__(self, descriptions, svmModel, biasToCntr=False): | ||
self.descriptions = descriptions | ||
self.svm = svmModel['svm'] | ||
self.whitenParams = svmModel['whitenParams'] | ||
self.biasToCntr = biasToCntr | ||
nFeatures = np.sum([ | ||
d['desc'][-1][0][1]['initialize']['n_filters'] | ||
for d in self.descriptions if d != None | ||
]) | ||
diff = self.svm.get_nr_feature() - nFeatures | ||
if diff != 0: | ||
if diff == 1 and not biasToCntr: | ||
raise ValueError("The number of features in eDN and svm " | ||
"models does not match! Is the center bias " | ||
"correctly set?") | ||
|
||
def saliency(self, img, normalize=True): | ||
"""Computes eDN saliency map for single image or image sequence""" | ||
|
||
descs = self.descriptions | ||
|
||
# rescale image to typical input size | ||
imgSize = img.shape[:2] | ||
rescale_factor = 0.5*EDN_INSIZE[0]/max(imgSize) + \ | ||
0.5*EDN_INSIZE[1]/min(imgSize) | ||
# single image: | ||
# img = misc.imresize(image, rescale_factor, 'bicubic') | ||
|
||
# image sequence (or single image) | ||
scaledImg = np.zeros([a * rescale_factor | ||
for a in imgSize] + [img.shape[2]]) | ||
for j in xrange(img.shape[2] / 3): | ||
scaledImg[:, :, j * 3:j * 3 + 3] = misc.imresize( | ||
img[:, :, j * 3:j * 3 + 3], rescale_factor, 'bicubic') | ||
img = scaledImg | ||
# compute eDN features for description(s) | ||
t1 = time.time() | ||
fMapEDN, fMapSize = eDN_features(img, descs) | ||
t2 = time.time() | ||
logging.info("Feature computation took %0.3fs" % (t2 - t1)) | ||
print('fMapSize', fMapSize) | ||
if self.biasToCntr: | ||
fMapCntr = dist_to_cntr_features(img, fMapSize) | ||
fMap = np.hstack((fMapCntr, fMapEDN)) | ||
else: | ||
fMap = fMapEDN | ||
|
||
fMapW, fwParams = whiten_features(fMap, self.whitenParams) | ||
|
||
# SVM prediction | ||
t1 = time.time() | ||
bs, pAcc, pred = predict([], fMapW.tolist(), self.svm, options="-q") | ||
t2 = time.time() | ||
logging.info("Prediction took %0.3fs" % (t2 - t1)) | ||
pred = np.array(pred) | ||
|
||
# reshaping and upscaling | ||
pred = pred.reshape(fMapSize, order='F') | ||
predLarge = sp.ndimage.interpolation.zoom( | ||
pred, (imgSize[0] / float(pred.shape[0]), | ||
imgSize[1] / float(pred.shape[1]))) | ||
|
||
# normalization | ||
if normalize: | ||
rescaled = (255.0 / (predLarge.max() - predLarge.min()) * | ||
(predLarge - predLarge.min())).astype(np.uint8) | ||
return rescaled | ||
else: | ||
return predLarge |
Oops, something went wrong.