commit
31e9605777
26 changed files with 124 additions and 694 deletions
@ -1,44 +0,0 @@ |
||||
set(GoogleNet_url "http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel") |
||||
set(GoogleNet_dst "$ENV{OPENCV_TEST_DATA_PATH}/dnn/bvlc_googlenet.caffemodel") |
||||
set(GoogleNet_sha "405fc5acd08a3bb12de8ee5e23a96bec22f08204") |
||||
|
||||
set(VGG16_url "http://www.robots.ox.ac.uk/~vgg/software/very_deep/caffe/VGG_ILSVRC_16_layers.caffemodel") |
||||
set(GG16_dst "$ENV{OPENCV_TEST_DATA_PATH}/dnn/VGG_ILSVRC_16_layers.caffemodel") |
||||
|
||||
set(voc-fcn32s_url "http://dl.caffe.berkeleyvision.org/fcn32s-heavy-pascal.caffemodel") |
||||
set(voc-fcn32s_dst "$ENV{OPENCV_TEST_DATA_PATH}/dnn/fcn32s-heavy-pascal.caffemodel") |
||||
|
||||
set(Alexnet_url "http://dl.caffe.berkeleyvision.org/bvlc_alexnet.caffemodel") |
||||
set(Alexnet_dst "$ENV{OPENCV_TEST_DATA_PATH}/dnn/bvlc_alexnet.caffemodel") |
||||
set(Alexnet_sha "9116a64c0fbe4459d18f4bb6b56d647b63920377") |
||||
|
||||
set(Inception_url "https://github.com/petewarden/tf_ios_makefile_example/raw/master/data/tensorflow_inception_graph.pb") |
||||
set(Inception_dst "$ENV{OPENCV_TEST_DATA_PATH}/dnn/tensorflow_inception_graph.pb") |
||||
|
||||
set(Enet_url "https://www.dropbox.com/sh/dywzk3gyb12hpe5/AABoUwqQGWvClUu27Z1EWeu9a/model-best.net?dl=0") |
||||
set(Enet_dst "$ENV{OPENCV_TEST_DATA_PATH}/dnn/Enet-model-best.net") |
||||
|
||||
set(Fcn_url "http://dl.caffe.berkeleyvision.org/fcn8s-heavy-pascal.caffemodel") |
||||
set(Fcn_dst "$ENV{OPENCV_TEST_DATA_PATH}/dnn/fcn8s-heavy-pascal.caffemodel") |
||||
|
||||
if(NOT model) |
||||
set(model "GoogleNet") |
||||
endif() |
||||
|
||||
message(STATUS "Downloading ${${model}_url} to ${${model}_dst}") |
||||
|
||||
if(NOT EXISTS ${${model}_dst}) |
||||
if(${${model}_sha}) |
||||
file(DOWNLOAD ${${model}_url} ${${model}_dst} SHOW_PROGRESS EXPECTED_HASH SHA1=${${model}_sha} STATUS status_vec) |
||||
else() |
||||
file(DOWNLOAD ${${model}_url} ${${model}_dst} SHOW_PROGRESS STATUS status_vec) |
||||
endif() |
||||
|
||||
list(GET status_vec 0 status) |
||||
list(GET status_vec 1 status_msg) |
||||
if(status EQUAL 0) |
||||
message(STATUS "Ok! ${status_msg}") |
||||
else() |
||||
message(STATUS "Fail! ${status_msg}") |
||||
endif() |
||||
endif() |
@ -1,51 +0,0 @@ |
||||
set(PROTOBUF_CPP_NAME "libprotobuf") |
||||
set(PROTOBUF_CPP_DOWNLOAD_HASH "bd5e3eed635a8d32e2b99658633815ef") |
||||
set(PROTOBUF_CPP_PATH "${CMAKE_CURRENT_BINARY_DIR}/3rdparty/protobuf/sources") # /protobuf-3.1.0 subdirectory |
||||
|
||||
set(OPENCV_PROTOBUF_CPP_DOWNLOAD_URL ${OPENCV_PROTOBUF_URL};$ENV{OPENCV_PROTOBUF_URL};https://github.com/google/protobuf/releases/download/) |
||||
|
||||
function(ocv_protobuf_download file ID) |
||||
if(DEFINED ${ID}_DOWNLOADED_HASH |
||||
AND ${ID}_DOWNLOADED_HASH STREQUAL ${ID}_DOWNLOAD_HASH |
||||
AND EXISTS ${${ID}_PATH}) |
||||
# Files have been downloaded and checked by the previous CMake run |
||||
return() |
||||
else() |
||||
if(EXISTS ${${ID}_PATH}) |
||||
message(STATUS "${${ID}_NAME}: Removing previous unpacked files: ${${ID}_PATH}") |
||||
file(REMOVE_RECURSE ${${ID}_PATH}) |
||||
endif() |
||||
endif() |
||||
unset(${ID}_DOWNLOADED_HASH CACHE) |
||||
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/.download) |
||||
file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/.download/.gitignore" "*\n") |
||||
ocv_download(PACKAGE ${file} |
||||
HASH ${${ID}_DOWNLOAD_HASH} |
||||
URL ${OPENCV_${ID}_DOWNLOAD_URL} |
||||
DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/.download) |
||||
set(${ID}_ARCHIVE "${DOWNLOAD_PACKAGE_LOCATION}") |
||||
|
||||
ocv_assert(EXISTS "${${ID}_ARCHIVE}") |
||||
ocv_assert(NOT EXISTS "${${ID}_PATH}") |
||||
file(MAKE_DIRECTORY ${${ID}_PATH}) |
||||
ocv_assert(EXISTS "${${ID}_PATH}") |
||||
file(WRITE "${${ID}_PATH}/.gitignore" "*\n") |
||||
|
||||
message(STATUS "${${ID}_NAME}: Unpacking ${file} to ${${ID}_PATH}...") |
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xz "${${ID}_ARCHIVE}" |
||||
WORKING_DIRECTORY "${${ID}_PATH}" |
||||
RESULT_VARIABLE __result) |
||||
|
||||
if(NOT __result EQUAL 0) |
||||
message(FATAL_ERROR "${${ID}_NAME}: Failed to unpack ${ID} archive from ${${ID}_ARCHIVE} to ${${ID}_PATH} with error ${__result}") |
||||
endif() |
||||
|
||||
ocv_assert(EXISTS "${${ID}_PATH}") |
||||
|
||||
set(${ID}_DOWNLOADED_HASH "${${ID}_DOWNLOAD_HASH}" CACHE INTERNAL "${ID} hash") |
||||
|
||||
#message(STATUS "${${ID}_NAME}: Successfully downloaded") |
||||
endfunction() |
||||
|
||||
ocv_protobuf_download(v3.1.0/protobuf-cpp-3.1.0.tar.gz PROTOBUF_CPP) |
@ -1 +0,0 @@ |
||||
*.caffemodel |
@ -1,39 +0,0 @@ |
||||
name: "test_Convolution" |
||||
input: "input" |
||||
|
||||
input_dim: 2 |
||||
input_dim: 6 |
||||
input_dim: 75 |
||||
input_dim: 113 |
||||
|
||||
layer { |
||||
type: "Convolution" |
||||
|
||||
convolution_param |
||||
{ |
||||
group: 3 |
||||
num_output: 12 |
||||
|
||||
pad_h: 0 |
||||
pad_w: 1 |
||||
kernel_h: 4 |
||||
kernel_w: 5 |
||||
stride_h: 2 |
||||
stride_w: 3 |
||||
|
||||
weight_filler{ |
||||
type: 'uniform' |
||||
min: -1 |
||||
max: 1 |
||||
} |
||||
bias_filler { |
||||
type: 'uniform' |
||||
min: -1 |
||||
max: 1 |
||||
} |
||||
} |
||||
|
||||
name: "output" |
||||
bottom: "input" |
||||
top: "output" |
||||
} |
@ -1,39 +0,0 @@ |
||||
name: "test_Convolution" |
||||
input: "input" |
||||
|
||||
input_dim: 2 |
||||
input_dim: 12 |
||||
input_dim: 36 |
||||
input_dim: 37 |
||||
|
||||
layer { |
||||
type: "Deconvolution" |
||||
|
||||
convolution_param |
||||
{ |
||||
group: 3 |
||||
num_output: 12 |
||||
|
||||
pad_h: 0 |
||||
pad_w: 1 |
||||
kernel_h: 4 |
||||
kernel_w: 5 |
||||
stride_h: 2 |
||||
stride_w: 3 |
||||
|
||||
weight_filler{ |
||||
type: 'uniform' |
||||
min: -1 |
||||
max: 1 |
||||
} |
||||
bias_filler { |
||||
type: 'uniform' |
||||
min: -1 |
||||
max: 1 |
||||
} |
||||
} |
||||
|
||||
name: "output" |
||||
bottom: "input" |
||||
top: "output" |
||||
} |
@ -1,32 +0,0 @@ |
||||
name: "test_InnerProduct" |
||||
input: "input" |
||||
|
||||
input_dim: 2 |
||||
input_dim: 6 |
||||
input_dim: 75 |
||||
input_dim: 113 |
||||
|
||||
layer { |
||||
type: "InnerProduct" |
||||
|
||||
inner_product_param |
||||
{ |
||||
axis: 3 |
||||
num_output: 2 |
||||
|
||||
weight_filler{ |
||||
type: 'uniform' |
||||
min: -1 |
||||
max: 1 |
||||
} |
||||
bias_filler { |
||||
type: 'uniform' |
||||
min: -1 |
||||
max: 1 |
||||
} |
||||
} |
||||
|
||||
name: "output" |
||||
bottom: "input" |
||||
top: "output" |
||||
} |
@ -1,21 +0,0 @@ |
||||
name: "test_LRN_channels" |
||||
input: "input" |
||||
|
||||
input_dim: 2 |
||||
input_dim: 6 |
||||
input_dim: 75 |
||||
input_dim: 113 |
||||
|
||||
layer { |
||||
type: "LRN" |
||||
lrn_param { |
||||
norm_region: ACROSS_CHANNELS; |
||||
local_size: 5 |
||||
alpha: 1.1 |
||||
beta: 0.75 |
||||
} |
||||
|
||||
name: "output" |
||||
bottom: "input" |
||||
top: "output" |
||||
} |
@ -1,22 +0,0 @@ |
||||
name: "test_LRN_spatial" |
||||
input: "input" |
||||
|
||||
input_dim: 2 |
||||
input_dim: 6 |
||||
input_dim: 75 |
||||
input_dim: 113 |
||||
|
||||
layer { |
||||
type: "LRN" |
||||
|
||||
lrn_param { |
||||
norm_region: WITHIN_CHANNEL; |
||||
local_size: 5 |
||||
alpha: 0.9 |
||||
beta: 0.75 |
||||
} |
||||
|
||||
name: "output" |
||||
bottom: "input" |
||||
top: "output" |
||||
} |
@ -1,21 +0,0 @@ |
||||
name: "test_MVN_channels" |
||||
input: "input" |
||||
|
||||
input_dim: 2 |
||||
input_dim: 6 |
||||
input_dim: 75 |
||||
input_dim: 113 |
||||
|
||||
layer { |
||||
type: "MVN" |
||||
|
||||
mvn_param { |
||||
eps: 0.1 |
||||
across_channels: false |
||||
normalize_variance: true |
||||
} |
||||
|
||||
name: "output" |
||||
bottom: "input" |
||||
top: "output" |
||||
} |
@ -1,26 +0,0 @@ |
||||
name: "test_Pooling_max" |
||||
input: "input" |
||||
|
||||
input_dim: 2 |
||||
input_dim: 6 |
||||
input_dim: 75 |
||||
input_dim: 113 |
||||
|
||||
layer { |
||||
type: "Pooling" |
||||
|
||||
pooling_param |
||||
{ |
||||
pool: AVE |
||||
pad_h: 2 |
||||
pad_w: 1 |
||||
kernel_h: 3 |
||||
kernel_w: 5 |
||||
stride_h: 2 |
||||
stride_w: 1 |
||||
} |
||||
|
||||
name: "output" |
||||
bottom: "input" |
||||
top: "output" |
||||
} |
@ -1,26 +0,0 @@ |
||||
name: "test_Pooling_max" |
||||
input: "input" |
||||
|
||||
input_dim: 2 |
||||
input_dim: 6 |
||||
input_dim: 75 |
||||
input_dim: 113 |
||||
|
||||
layer { |
||||
type: "Pooling" |
||||
|
||||
pooling_param |
||||
{ |
||||
pool: MAX |
||||
pad_h: 2 |
||||
pad_w: 1 |
||||
kernel_h: 3 |
||||
kernel_w: 5 |
||||
stride_h: 2 |
||||
stride_w: 1 |
||||
} |
||||
|
||||
name: "output" |
||||
bottom: "input" |
||||
top: "output" |
||||
} |
@ -1,15 +0,0 @@ |
||||
name: "test_Softmax" |
||||
input: "input" |
||||
|
||||
input_dim: 2 |
||||
input_dim: 6 |
||||
input_dim: 75 |
||||
input_dim: 113 |
||||
|
||||
layer { |
||||
type: "Softmax" |
||||
|
||||
name: "output" |
||||
bottom: "input" |
||||
top: "output" |
||||
} |
@ -1,77 +0,0 @@ |
||||
name: "test_reshape_splice_split" |
||||
input: "input" |
||||
|
||||
layer{ |
||||
type: "Split" |
||||
name: "dummy_split" |
||||
bottom: "input" |
||||
top: "dummy_split_0" |
||||
top: "dummy_split_1" |
||||
} |
||||
layer{ |
||||
type: "Slice" |
||||
name: "dummy_slice_0" |
||||
bottom: "dummy_split_0" |
||||
slice_param{ |
||||
slice_point: 1 |
||||
slice_point: 2 |
||||
} |
||||
top: "dummy_slice_0_0" |
||||
top: "dummy_slice_0_1" |
||||
top: "dummy_slice_0_2" |
||||
} |
||||
layer{ |
||||
type: "Slice" |
||||
name: "dummy_slice_1" |
||||
bottom: "dummy_split_1" |
||||
slice_param{ |
||||
slice_point: 1 |
||||
slice_point: 2 |
||||
} |
||||
top: "dummy_slice_1_0" |
||||
top: "dummy_slice_1_1" |
||||
top: "dummy_slice_1_2" |
||||
} |
||||
layer{ |
||||
type: "Sigmoid" |
||||
name: "alter_sliced_split" |
||||
bottom: "dummy_slice_1_2" |
||||
top: "dummy_slice_1_2" |
||||
} |
||||
layer{ |
||||
type: "Concat" |
||||
name: "dummy_concat" |
||||
bottom: "dummy_slice_0_0" |
||||
bottom: "dummy_slice_1_1" |
||||
bottom: "dummy_slice_0_2" |
||||
top: "dummy_concat" |
||||
} |
||||
layer{ |
||||
type: "Reshape" |
||||
name: "dummy_reshape" |
||||
bottom: "dummy_concat" |
||||
reshape_param{ |
||||
shape{ |
||||
dim: 0 |
||||
dim: 1 |
||||
dim: 1 |
||||
dim: -1 |
||||
dim: 1 |
||||
} |
||||
axis: 1 |
||||
num_axes: 1 |
||||
} |
||||
top: "dummy_reshape" |
||||
} |
||||
layer{ |
||||
type: "Flatten" |
||||
name: "dummy_reshape_undo" |
||||
bottom: "dummy_reshape" |
||||
top: "dummy_reshape_undo" |
||||
} |
||||
layer{ |
||||
type: "Split" |
||||
name: "output" |
||||
bottom: "dummy_reshape_undo" |
||||
top: "output" |
||||
} |
@ -1,45 +0,0 @@ |
||||
# coding: utf-8 |
||||
|
||||
import sys, os, glob |
||||
|
||||
CAFFE_ROOT = "/home/vitaliy/opencv/caffe/" |
||||
sys.path.insert(0, CAFFE_ROOT + 'python') |
||||
|
||||
import numpy as np |
||||
import caffe |
||||
#import cv2 |
||||
|
||||
def get_cafe_output(inp_blob, proto_name, caffemodel_name): |
||||
caffe.set_mode_cpu() |
||||
net = caffe.Net(proto_name, caffe.TEST) |
||||
|
||||
#net.blobs['input'].reshape(*inp_blob.shape) |
||||
net.blobs['input'].data[...] = inp_blob |
||||
|
||||
net.forward() |
||||
out_blob = net.blobs['output'].data[...]; |
||||
|
||||
if net.params.get('output'): |
||||
print "Params count:", len(net.params['output']) |
||||
net.save(caffemodel_name) |
||||
|
||||
return out_blob |
||||
|
||||
if __name__ == '__main__': |
||||
proto_filenames = glob.glob("layer_*.prototxt") |
||||
|
||||
for proto_filename in proto_filenames: |
||||
proto_filename = os.path.basename(proto_filename) |
||||
proto_basename = os.path.splitext(proto_filename)[0] |
||||
cfmod_basename = proto_basename + ".caffemodel" |
||||
npy_filename = proto_basename + ".npy" |
||||
|
||||
inp_blob_name = proto_basename + ".input.npy" |
||||
inp_blob = np.load(inp_blob_name) if os.path.exists(inp_blob_name) else np.load('blob.npy') |
||||
|
||||
print "\nGenerate data for:" |
||||
print cfmod_basename, inp_blob.shape |
||||
|
||||
out_blob = get_cafe_output(inp_blob, proto_filename, cfmod_basename) |
||||
print out_blob.shape |
||||
np.save(npy_filename, out_blob) |
@ -1,91 +0,0 @@ |
||||
import 'nn' |
||||
|
||||
function fill_net(net) |
||||
if net.modules then |
||||
for i = 1, #net.modules do |
||||
fill_net(net.modules[i]) |
||||
end |
||||
end |
||||
if net.weight then |
||||
net.weight = torch.rand(net.weight:size()) |
||||
end |
||||
if net.bias then |
||||
net.bias = torch.rand(net.bias:size()) |
||||
end |
||||
if net.train then |
||||
net.train = 0 |
||||
end |
||||
end |
||||
|
||||
function save(net, input, label) |
||||
fill_net(net) |
||||
output = net:forward(input) |
||||
|
||||
--torch.save(label .. '_net.dat', net) |
||||
torch.save(label .. '_net.txt', net, 'ascii') |
||||
--torch.save(label .. '_input.dat', input) |
||||
torch.save(label .. '_input.txt', input, 'ascii') |
||||
--torch.save(label .. '_output.dat', output) |
||||
torch.save(label .. '_output.txt', output, 'ascii') |
||||
|
||||
return net |
||||
end |
||||
|
||||
local net_simple = nn.Sequential() |
||||
net_simple:add(nn.ReLU()) |
||||
net_simple:add(nn.SpatialConvolution(3,64, 11,7, 3,4, 3,2)) |
||||
net_simple:add(nn.SpatialMaxPooling(4,5, 3,2, 1,2)) |
||||
net_simple:add(nn.Sigmoid()) |
||||
save(net_simple, torch.Tensor(2, 3, 25, 35), 'net_simple') |
||||
|
||||
local net_pool_max = nn.Sequential() |
||||
net_pool_max:add(nn.SpatialMaxPooling(4,5, 3,2, 1,2):ceil()) --TODO: add ceil and floor modes |
||||
local net = save(net_pool_max, torch.rand(2, 3, 50, 30), 'net_pool_max') |
||||
torch.save('net_pool_max_output_2.txt', net.modules[1].indices - 1, 'ascii') |
||||
|
||||
local net_pool_ave = nn.Sequential() |
||||
net_pool_ave:add(nn.SpatialAveragePooling(4,5, 2,1, 1,2)) |
||||
save(net_pool_ave, torch.rand(2, 3, 50, 30), 'net_pool_ave') |
||||
|
||||
local net_conv = nn.Sequential() |
||||
net_conv:add(nn.SpatialConvolution(3,64, 11,7, 3,4, 3,2)) |
||||
save(net_conv, torch.rand(1, 3, 50, 60), 'net_conv') |
||||
|
||||
local net_reshape = nn.Sequential() |
||||
net_reshape:add(nn.Reshape(5, 4, 3, 2)) |
||||
save(net_reshape, torch.rand(2, 3, 4, 5), 'net_reshape') |
||||
|
||||
local net_reshape_batch = nn.Sequential() |
||||
net_reshape_batch:add(nn.Reshape(5, 4, 3, true)) |
||||
save(net_reshape_batch, torch.rand(2, 3, 4, 5), 'net_reshape_batch') |
||||
|
||||
save(nn.Linear(7, 3), torch.rand(13, 7), 'net_linear_2d') |
||||
|
||||
local net_parallel = nn.Parallel(4, 2) |
||||
net_parallel:add(nn.Sigmoid()) |
||||
net_parallel:add(nn.Tanh()) |
||||
save(net_parallel, torch.rand(2, 6, 4, 2), 'net_parallel') |
||||
|
||||
local net_concat = nn.Concat(2) |
||||
net_concat:add(nn.ReLU()) |
||||
net_concat:add(nn.Tanh()) |
||||
net_concat:add(nn.Sigmoid()) |
||||
save(net_concat, torch.rand(2, 6, 4, 3) - 0.5, 'net_concat') |
||||
|
||||
local net_deconv = nn.Sequential() |
||||
net_deconv:add(nn.SpatialFullConvolution(3, 9, 4, 5, 1, 2, 0, 1, 0, 1)) |
||||
save(net_deconv, torch.rand(2, 3, 4, 3) - 0.5, 'net_deconv') |
||||
|
||||
local net_batch_norm = nn.Sequential() |
||||
net_batch_norm:add(nn.SpatialBatchNormalization(4, 1e-3)) |
||||
save(net_batch_norm, torch.rand(1, 4, 5, 6) - 0.5, 'net_batch_norm') |
||||
|
||||
local net_prelu = nn.Sequential() |
||||
net_prelu:add(nn.PReLU(5)) |
||||
save(net_prelu, torch.rand(1, 5, 40, 50) - 0.5, 'net_prelu') |
||||
|
||||
local net_cadd_table = nn.Sequential() |
||||
local sum = nn.ConcatTable() |
||||
sum:add(nn.Identity()):add(nn.Identity()) |
||||
net_cadd_table:add(sum):add(nn.CAddTable()) |
||||
save(net_cadd_table, torch.rand(1, 5, 40, 50) - 0.5, 'net_cadd_table') |
@ -1,2 +0,0 @@ |
||||
require 'nn' |
||||
print("nn module exists!") |
@ -1,4 +1,14 @@ |
||||
set(the_description "Contributed/Experimental Algorithms for Salient 2D Features Detection") |
||||
|
||||
ocv_define_module(xfeatures2d opencv_core opencv_imgproc opencv_features2d opencv_calib3d OPTIONAL opencv_shape opencv_cudaarithm WRAP python java) |
||||
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/download_vgg.cmake) |
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/download_boostdesc.cmake) |
||||
set(DOWNLOAD_DIR "${OpenCV_BINARY_DIR}/downloads/xfeatures2d") |
||||
download_boost_descriptors("${DOWNLOAD_DIR}" boost_status) |
||||
download_vgg_descriptors("${DOWNLOAD_DIR}" vgg_status) |
||||
if(NOT boost_status OR NOT vgg_status) |
||||
ocv_module_disable(xfeatures2d) |
||||
endif() |
||||
|
||||
ocv_module_include_directories("${DOWNLOAD_DIR}") |
||||
|
Loading…
Reference in new issue