Coder Social home page Coder Social logo

torch-opencv-demos's People

Contributors

shrubb avatar szagoruyko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

torch-opencv-demos's Issues

How to crop a Mat ?!

Hi, thanks for the project!, I'm trying to crop a cv::Mat

img(cv::Rect(xMin,yMin,xMax-xMin,yMax-yMin)).copyTo(croppedImg);

How can i do this ?

Thank in advance

switch on gpu

Please, for dummies, how use GPU in imagenet_classification demo?

MNIST /LENET

Can you provide and example for MNIST / LENET ?

Thanks

FloatTensor have no less-than operator

  local gender_out = gender_net:forward(I)
  **local gender = gender_out[1] > gender_out[2] and 'M' or 'F'**

  local age_out = age_net:forward(I)
  local _,id = age_out:max(1)
  **local age = ages[id[1] ]**

Thank you for providing such a good demo about opencv

I try to use this age_gender demo type but have some problem

In bold line, they print out an error message.

(gender_out[1] > gender_out[2]) -> FloatTensor have no less-than operator

ages[id[1]] -> attempt to concatenate local 'age' (a nil value)

image

image

I cannot install in here:

I cannot install in here:
"OpenCV_DIR=/usr/local/Cellar/opencv3/3.1.0/share/OpenCV luarocks install cv"

My Error Message Gere:
"Error: No results matching query were found."

What's wrong with me?

MY
H/W: Macbook Pro 2012Late i7
S/W: El Capitan

How to load saved images in gallery to show the already trained person

Hi All,

How to load saved images in gallery to show the already trained person. I need to show the trained people again in gallery if the whole system/demo restarted.

After a long research, I could not find a way to load a image in gallery which was saved on disk before restart of demo.

local img = image.load(file, 3, 'byte')

local faceInGallery = gallery
:narrow(1, 1 + thumbnailSize*(currentPerson-1), thumbnailSize)
:narrow(2, 101 + thumbnailSize * #people[currentPerson], thumbnailSize)

-- show image in gallery
cv.resize{ img , {thumbnailSize, thumbnailSize}, dst=faceInGallery}

Please help me to show image in cv.resize which can be displayed in gallery.

Thanks
Bharat Bhushan

File already exists in database: caffe.proto error

Hello,
Please Help!!!
OS: Mac OS Sierra
Open CV: 3.0.0
protobuf: 3.1.0

When i am trying to run the age-gender detection code, i am getting the following error:
[libprotobuf ERROR google/protobuf/descriptor_database.cc:57] File already exists in database: caffe.proto
[libprotobuf FATAL google/protobuf/descriptor.cc:1272] CHECK failed: generated_database_->Add(encoded_file_descriptor, size):
libc++abi.dylib: terminating with uncaught exception of type google::protobuf::FatalException: CHECK failed: generated_database_->Add(encoded_file_descriptor, size):
Abort trap: 6

This is happening when i try require cv after require load caffe or the other way round. Please help me solve this issue. I am stuck since two days debugging this bad boy

face_recognition demo: segmentation fault error

Running into segmentation fault errors with face_recognition and age_gender demos using the webcam.

System:
Nvidia TX1
4 GB RAM
Ubuntu 16
opencv 3.1 with cuda


nvidia@tegra-ubuntu:~/torch-opencv-demos/age_gender$ th demo.lua camera
Looking for haarcascades/haarcascade_frontalface_default.xml...
Successfully loaded ./gender_net.caffemodel
Successfully loaded ./age_net.caffemodel
Segmentation fault

"input.dims() == 4 error", How to convert Mat(2 dims) to 4 dims

Hello Everyone:
I'm testing "gender_net.caffemodel" with Opencv in C++, like this:
Mat img1 = imread("1.jpg",0);//read a gray image
resize(img1, img1, Size(227, 227));
Mat img2;
img1.convertTo(img2, CV_32F);

dnn::Blob inputBlob = dnn::Blob(img2);
net.setBlob(".data", inputBlob); //set the network input
net.forward();

    when run "net.forward();", take failed:

OpenCV Error: Assertion failed (input.dims() == 4
So,I want to know, How to convert Mat(2 dims) to 4 dims in C++
Thanks!

module 'cv' not found:No LuaRocks module found for cv

I hope that you don't mind: I'm adding these issues (that I encountered earlier) and my solutions, as it pertains specifically to this project/repo. It may help others.

I already posted my solution here torch-opencv - Issue#122.

Basically, I had torch7 already installed on Arch Linux for OpenFace work. I then encountered the

module 'cv' not found:No LuaRocks module found for cv

error when trying to work with this torch-opencv-demos repo -- additionally with error output virtually identical to that reported by user "anthonyyuan", May 09 in that torch-opencv - Issue#122 issue/thread.

My solution was to install "luarocks" in Arch Linux,

sudo pacman -S luarocks

followed by

luarocks install cv

My motivation for the last statement was hughperkins Aug 03 comment in the Issue #6 thread, here.

I hope it helps others. :-)

  • My system: Arch Linux x86_64 , Intel Core i7-4790 CPU
  • Environment: Anaconda Python 2.7 virtual environment
  • Torch7: installed from GitHub repo: https://github.com/torch/torch7
  • OpenCV: installed from GitHub repo: https://github.com/opencv/opencv
  • Relevant installations (my cloned GitHub repos|directories):
    • /mnt/Vancouver/apps/lua-cjson
    • /mnt/Vancouver/apps/neuraltalk2
    • /mnt/Vancouver/apps/torch-opencv-demos
    • /mnt/Vancouver/apps/torch7

Update 1 -- age_gender demo:

I also had to do

luarocks install loadcaffe

for the second (age_gender) demo, and run as

th demo.lua camera    ## webcam

not

th demo.lua `locate haarcascade_frontalface_default.xml`

Update 2 -- NeuralTalk2 demo:

Installations [/mnt/Vancouver/apps/neuraltalk2]:

luarocks install nn
luarocks install nngraph
luarocks install image
# luarocks install loadcaffe      ## only if you want to train a model (I installed)
luarocks install hdf5

Also required: lua-cjson [/mnt/Vancouver/apps/lua-cjson]:

* download: https://www.kyne.com.au/~mark/software/lua-cjson.php
* instructions: https://www.kyne.com.au/~mark/software/lua-cjson-manual.html#_luarocks
* extract, install:

    cd lua-cjson-2.1.0
    luarocks make           ## still in ## p2 venv

Test run [/mnt/Vancouver/apps/neuraltalk2/]:

th videocaptioning.lua

/mnt/Vancouver/apps/torch7/install/bin/luajit: ...ncouver/apps/torch7/install/share/lua/5.1/trepl
/init.lua:389: ...ncouver/apps/torch7/install/share/lua/5.1/trepl/init.lua:389: ...Vancouver/apps/
torch7/install/share/lua/5.1/hdf5/ffi.lua:42: Error: unable to locate HDF5 header file at hdf5.h
stack traceback:
    [C]: in function 'error'
    ...ncouver/apps/torch7/install/share/lua/5.1/trepl/init.lua:389: in function 'require'
    videocaptioning.lua:7: in main chunk
    [C]: in function 'dofile'
    ...pps/torch7/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
    [C]: at 0x00405b80


th -e "require 'hdf5'"

...ncouver/apps/torch7/install/share/lua/5.1/trepl/init.lua:389: ...Vancouver/apps/torch7/
install/share/lua/5.1/hdf5/ffi.lua:42: Error: unable to locate HDF5 header file at hdf5.h

which hdf5
    which: no hdf5 in
    ...

whereis hdf5
    hdf5: /usr/include/hdf5.h
  • EDIT/include path to hdf5.h :

    /mnt/Vancouver/apps/torch7/install/share/lua/5.1/hdf5/config.lua :

    hdf5._config = {
    HDF5_INCLUDE_PATH = "/usr/include/",
    HDF5_LIBRARIES = "/usr/lib64/libhdf5.so;/usr/lib64/librt.so;/usr/lib64/libz.so;
    /usr/lib64/libdl.so;/usr/lib64/libm.so"
    }

i.e. changed

HDF5_INCLUDE_PATH = "",

to

HDF5_INCLUDE_PATH = "/usr/include/",

as that is where hdf5.h is:

(py27) [victoria@victoria neuraltalk2]$ whereis hdf5

    hdf5: /usr/include/hdf5.h

(py27) [victoria@victoria neuraltalk2]$
  • NEXT problem:

    th videocaptioning.lua

    /mnt/Vancouver/apps/torch7/install/bin/luajit: ...ncouver/apps/torch7/install/share/lua/
    5.1/trepl/init.lua:389: ...ncouver/apps/torch7/install/share/lua/5.1/trepl/init.lua:389:
    ...Vancouver/apps/torch7/install/share/lua/5.1/hdf5/ffi.lua:71: Unsupported HDF5
    version: 1.10.0
    stack traceback:
    [C]: in function 'error'
    ...ncouver/apps/torch7/install/share/lua/5.1/trepl/init.lua:389: in function 'require'
    videocaptioning.lua:7: in main chunk
    [C]: in function 'dofile'
    ...pps/torch7/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
    [C]: at 0x00405b80

  • Edit line 71 in: /mnt/Vancouver/apps/torch7/install/share/lua/5.1/hdf5/ffi.lua :
    ...
    hdf5.ffi = ffi

    -- Victoria -- commented out the following line:
    --checkHDF5Version()
    ...

  • Now:

    (py27) [victoria@victoria neuraltalk2]$ th -e "require 'hdf5'"

    (py27) [victoria@victoria neuraltalk2]$

  • So far so good!

    https://github.com/karpathy/neuraltalk2
    I just want to caption images
    ...
    "I only have CPU". Okay, in that case download the cpu model checkpoint

      http://cs.stanford.edu/people/karpathy/neuraltalk2/checkpoint_v1_cpu.zip
    

    Make sure you run the eval script with

      -gpuid -1
    

    to tell the script to run on CPU. On my machine it takes a bit less than 1 second per image to caption in CPU mode.
    ...

[NeuralTalk2: live webcam] WORKS!

# https://github.com/szagoruyko/torch-opencv-demos/tree/master/neuraltalk2
# this (indicated on website, above) is deprecated:
# th videocaptioning.lua -gpuid -1 -model model_id1-501-1448236541_cpu.t7
# as the downloaded checkpoint file (above) gives a file with a sl. different name
# Use this:

th 2>/dev/null videocaptioning.lua -gpuid -1 -model model_id1-501-1448236541.t7_cpu.t7

Here is a (lossy) animated GIF:

neuraltalk2 - byzanz capture 2016-12-02 16 16 48

Reason: image not found

โžœ  age_gender git:(master) th demo.lua camera
/Users/wanghaisheng/torch/install/bin/luajit: .../wanghaisheng/torch/install/share/lua/5.1/trepl/init.lua:389: /Users/wanghaisheng/torch/install/share/lua/5.1/cv/init.lua:295: dlopen(/Users/wanghaisheng/torch/install/share/lua/5.1/cv/lib/libCommon.dylib, 5): Library not loaded: /usr/local/opt/ffmpeg/lib/libavcodec.56.dylib
  Referenced from: /usr/local/opt/opencv3/lib/libopencv_highgui.3.1.dylib
  Reason: image not found
stack traceback:
	[C]: in function 'error'
	.../wanghaisheng/torch/install/share/lua/5.1/trepl/init.lua:389: in function 'require'
	demo.lua:1: in main chunk
	[C]: in function 'dofile'
	...heng/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
	[C]: at 0x01005481a0

age_gender demo fails with segmentation fault

The age_gender demo fails with segmentation fault. Looks like the download links were updated recently:

nvidia@tegra-ubuntu:~/torch-opencv-demos/age_gender$ th demo.lua camera
Looking for haarcascades/haarcascade_frontalface_default.xml...
--2018-03-30 01:30:31-- https://github.com/eveningglow/age-and-gender-classification/raw/master/model/age_net.caffemodel
Resolving github.com (github.com)... 192.30.253.112, 192.30.253.113
Connecting to github.com (github.com)|192.30.253.112|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/eveningglow/age-and-gender-classification/master/model/age_net.caffemodel [following]
--2018-03-30 01:30:31-- https://raw.githubusercontent.com/eveningglow/age-and-gender-classification/master/model/age_net.caffemodel
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.200.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.200.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 45661480 (44M) [application/octet-stream]
Saving to: 'age_net.caffemodel'

age_net.caffemodel 100%[================================================================================================================>] 43.55M 2.98MB/s in 15s

2018-03-30 01:30:47 (2.99 MB/s) - 'age_net.caffemodel' saved [45661480/45661480]

--2018-03-30 01:30:47-- https://github.com/eveningglow/age-and-gender-classification/raw/master/model/gender_net.caffemodel
Resolving github.com (github.com)... 192.30.253.113, 192.30.253.112
Connecting to github.com (github.com)|192.30.253.113|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/eveningglow/age-and-gender-classification/master/model/gender_net.caffemodel [following]
--2018-03-30 01:30:47-- https://raw.githubusercontent.com/eveningglow/age-and-gender-classification/master/model/gender_net.caffemodel
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.200.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.200.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 45649168 (44M) [application/octet-stream]
Saving to: 'gender_net.caffemodel'

gender_net.caffemodel 100%[================================================================================================================>] 43.53M 2.98MB/s in 15s

2018-03-30 01:31:03 (3.00 MB/s) - 'gender_net.caffemodel' saved [45649168/45649168]

--2018-03-30 01:31:03-- https://github.com/eveningglow/age-and-gender-classification/raw/master/model/deploy_age2.prototxt
Resolving github.com (github.com)... 192.30.253.112, 192.30.253.113
Connecting to github.com (github.com)|192.30.253.112|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/eveningglow/age-and-gender-classification/master/model/deploy_age2.prototxt [following]
--2018-03-30 01:31:03-- https://raw.githubusercontent.com/eveningglow/age-and-gender-classification/master/model/deploy_age2.prototxt
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.200.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.200.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2324 (2.3K) [text/plain]
Saving to: 'deploy_age.prototxt'

deploy_age.prototxt 100%[================================================================================================================>] 2.27K --.-KB/s in 0s

2018-03-30 01:31:03 (13.0 MB/s) - 'deploy_age.prototxt' saved [2324/2324]

--2018-03-30 01:31:03-- https://github.com/eveningglow/age-and-gender-classification/raw/master/model/deploy_gender2.prototxt
Resolving github.com (github.com)... 192.30.253.113, 192.30.253.112
Connecting to github.com (github.com)|192.30.253.113|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/eveningglow/age-and-gender-classification/master/model/deploy_gender2.prototxt [following]
--2018-03-30 01:31:03-- https://raw.githubusercontent.com/eveningglow/age-and-gender-classification/master/model/deploy_gender2.prototxt
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.200.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.200.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2324 (2.3K) [text/plain]
Saving to: 'deploy_gender.prototxt'

deploy_gender.prototxt 100%[================================================================================================================>] 2.27K --.-KB/s in 0.001s

2018-03-30 01:31:04 (3.88 MB/s) - 'deploy_gender.prototxt' saved [2324/2324]

--2018-03-30 01:31:04-- https://www.dropbox.com/s/wa61ihl8l9z89e8/age_gender_mean.t7
Resolving www.dropbox.com (www.dropbox.com)... 162.125.6.1, 2620:100:601c:1::a27d:601
Connecting to www.dropbox.com (www.dropbox.com)|162.125.6.1|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://dl.dropboxusercontent.com/content_link/JSnZf8bzbYYjQqCC6Uk6kC2IH2ehxZwHTvY62E9JLVZLUZDDIb36lW4hDlYZ44N7/file [following]
--2018-03-30 01:31:04-- https://dl.dropboxusercontent.com/content_link/JSnZf8bzbYYjQqCC6Uk6kC2IH2ehxZwHTvY62E9JLVZLUZDDIb36lW4hDlYZ44N7/file
Resolving dl.dropboxusercontent.com (dl.dropboxusercontent.com)... 162.125.6.6, 2620:100:601c:6::a27d:606
Connecting to dl.dropboxusercontent.com (dl.dropboxusercontent.com)|162.125.6.6|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1573007 (1.5M) [application/octet-stream]
Saving to: 'age_gender_mean.t7'

age_gender_mean.t7 100%[================================================================================================================>] 1.50M 2.45MB/s in 0.6s

2018-03-30 01:31:06 (2.45 MB/s) - 'age_gender_mean.t7' saved [1573007/1573007]

Successfully loaded ./gender_net.caffemodel
MODULE data UNDEFINED
warning: module 'data [type 5]' not found
conv1: 96 3 7 7
conv2: 256 96 5 5
conv3: 384 256 3 3
fc6: 1 1 18816 512
fc7: 1 1 512 512
fc8: 1 1 512 2
Segmentation fault

Inconsistent README

In part of readme for age_gender classification, you are writing that locate should be executed, while software requires video source (video path or 'camera'), locate command is executed by demo.lua

Unknown predict face_recognition

Hi

We have predict functionality in face_recognition which somehow predict the person. But do we have unknown person functionality which person is not available in training?

Thanks
BB

Warning: Failed to load function from bytecode: (binary): cannot load incompatible

I am running into an error running the imagenet_classification demo (see error below):

System:
Nvidia TX1
4 GB RAM
Ubuntu 16
opencv 3.1 with cuda
Torch 7

nvidia@tegra-ubuntu:~/neuraltalk2$ luajit -v
LuaJIT 2.1.0-beta1 -- Copyright (C) 2005-2015 Mike Pall. http://luajit.org/

demo.lua:
print '==> Loading network'
-- Using network in network http://openreview.net/document/9b05a3bb-3a5e-49cb-91f7-0f482af65aea
local net = torch.load(network_name):unpack():float()
local synset_words = torch.load('synset.t7','ascii')


nvidia@tegra-ubuntu:~/torch-opencv-demos/imagenet_classification$ th demo.lua
==> Downloading image and network
image_name: Goldfish3.jpg
network_name: nin_nobn_final.t7
==> Loading network
Warning: Failed to load function from bytecode: (binary): cannot load incompatible bytecode/home/nvidia/torch/install/bin/luajit: demo.lua:29: attempt to call method 'unpack' (a nil value)
stack traceback:
demo.lua:29: in main chunk
[C]: in function 'dofile'
...idia/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: at 0x004061f0

having some trouble running the demo

hello everyone, I'm really new into torch and lua, and opencv and trying my best to learn by examples. but I can't make it to work. Here's my output

screen shot 2017-02-27 at 6 49 01 pm

Docker image

Using Docker gives you an ability to experiment with your code without any problems with installation and other dependency issues. I have created Docker image that let you do that.

https://github.com/riomus/torch-opencv-demos-docker

You can refer to it in your readme or create your Docker image in the same way.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.