Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MATLAB on Mac OS X is unable to find th #1

Closed
monabiyan opened this issue Sep 10, 2017 · 31 comments
Closed

MATLAB on Mac OS X is unable to find th #1

monabiyan opened this issue Sep 10, 2017 · 31 comments

Comments

@monabiyan
Copy link

monabiyan commented Sep 10, 2017

Hi
I am using mac , and have installed torch7 , MATLAB and NVIDIA GPU (CUDA 8.0) . When I run the run.m by MATLAB, I get the following results:
--------------------------------
~/vrn/face-alignment ~/vrn
/bin/bash: th: command not found
~/vrn
Landmarks extracted successfully.
/bin/bash: th: command not found
Error using run (line 70)
Failed to run Torch7 script.
-------------------------------
----

Looks like 'th' and CUDA works properly since it responds "Landmarks extracted successfully." but the second system call in the code gives this error. No idea what is this error from.
I greatly appreciate your help in advance!

@AaronJackson
Copy link
Owner

AaronJackson commented Sep 10, 2017

Hi monabiyan,

The "Landmarks extracted successfully" might actually be a small bug. It is possible that the return status is actually coming from popd, which is much less useful. (Edit: I've fixed this now)

The most likely issue, if Torch is installed correctly, is that it isn't in the PATH environment variable. Did you add it to your .bashrc file when the Torch installed asked? You can also try adding something like
system('. $HOME/distro/torch/bin/activate-torch')
at the top of run.m. Just be sure that that is actually the correct path.

Hope this helps.

@AaronJackson
Copy link
Owner

I am mistaken. The shell environment is not preserved between calls to system, so you have to add it to each block. Find your torch-activate script and then modify each system block to look like this:

retval = system(['cd face-alignment;' ...
                 '. ~/usr/local/torch/install/bin/torch-activate; ' ...
                 'CUDA_VISIBLE_DEVICES=' num2str(gpunum) ...
                 ' th main.lua -model 2D-FAN-300W.t7' ...
                 ' -input ../' input_folder ...
                 ' -detectFaces true' ...
                 ' -mode generate' ...
                 ' -output ../' input_folder ...
                 ' -outputFormat txt 2>&1 > /dev/null;']);

and

retval = system(['. ~/usr/local/torch/install/bin/torch-activate; ' ...
                 'CUDA_VISIBLE_DEVICES=' num2str(gpunum) ...
                 ' th ' pwd '/process.lua' ...
                 ' --model ' model_file ...
                 ' --input ' input_folder '/scaled/' ...
                 ' --output ' output_folder]);

This will activate torch for each call of system. Please also make sure you have it in your $HOME/.bashrc or $HOME/.profile file (I'm not sure which one Mac uses).

@monabiyan
Copy link
Author

monabiyan commented Sep 10, 2017

Hi @AaronJackson
I added the
system('. $HOME/distro/torch/bin/activate-torch')
command on top of the run.m file but it didn't work.
To prove that I have installed torch, I provided the following commands in terminal:

$cd
$th

and Here I get:

------------------------------------ 
 ______             __   |  Torch7 
 /_  __/__  ________/ /   |  Scientific computing for Lua. 
  / / / _ \/ __/ __/ _ \  |  Type ? for help 
 /_/  \___/_/  \__/_//_/  |  https://github.com/torch 
                          |  http://torch.ch 
---------------------------------------

So it is working. However, I also think it is not added in the path. In order to find the ".bashrc" file i provided the following commands in the terminal to show all the hidden files:

$cd
$ls -a 

surprisingly there is no ".bashrc" file in the file list appear.
So I think I should create this file and add the path. But can you help me on that?
what is the Path statement exactly I should add after creating the ".bashrc" myself.
BTW, I am using MacBook Pro (Retina, 13-inch, Early 2015) with macOS Sierra 10.12.6

@AaronJackson
Copy link
Owner

Possibly a MATLAB Mac quirk ignoring your environment. Please modify run.m as in my second comment and hopefully that will sort things for you. 😄

@AaronJackson AaronJackson changed the title Failed to run Torch7 script. MATLAB on Mac OS X is unable to find th Sep 10, 2017
@monabiyan
Copy link
Author

monabiyan commented Sep 10, 2017

Thanks, Aaron.

  1. I made sure that 'PATH=$PATH:/Users/you/torch/install/bin ; export PATH' (you=my macbook name) is added to my .bash_profile file. I followed the instructions provided at :
    [(https://stackoverflow.com/questions/30143308/torch-lua-after-installation-is-not-working)]

  2. I updated the run.m file with your new commands (replaced those tow pieces)

However, I am still getting error = 'Failed to run Torch7 script.' this time in the first part as well. :P

@monabiyan
Copy link
Author

I will try to reinstall torch again, that may solve the problem. ;)

@AaronJackson
Copy link
Owner

AaronJackson commented Sep 10, 2017

Remove the 2>&1 from the first system call so you can see stderr.

The torch-activate script does quite a bit more than augmenting the PATH. You need to run torch-activate in order to define some other variables, such as LUA_PATH.

Start by finding out where you installed Torch to:

(rogue) ~ $ which th
~/usr/local/torch/install/bin/th

Replacing the last part th with torch-activate to form the line

. ~/usr/local/torch/install/bin/torch-activate

which you need to use in each call of the system block as in my second comment. i.e.

retval = system(['cd face-alignment;' ...
                 '. ~/usr/local/torch/install/bin/torch-activate; ' ...
                 'CUDA_VISIBLE_DEVICES=' num2str(gpunum) ...
                 ' th main.lua -model 2D-FAN-300W.t7' ...
                 ' -input ../' input_folder ...
                 ' -detectFaces true' ...
                 ' -mode generate' ...
                 ' -output ../' input_folder ...
                 ' -outputFormat txt  ']);

If you do this, MATLAB will find torch.

@monabiyan
Copy link
Author

monabiyan commented Sep 10, 2017

Thank you, Aaron, I think I am getting very close !

  1. I removed '2>&1' from the first system call to see the error msg.
  2. In terminal I entered
    $ which th
    and found the address of my th which was different than your default suggestion:
    mine : "/Users/monabiyan/torch/install/bin/th"
    So I fixed that in both system calls in MATLAB.
    I no longer get error from that part. However, I am still getting a small error as following:
/bin/bash: th: command not found
Error using run (line 45)
Failed to run Torch7 script.

So "/bin/bash: th: command not found" is the main issue.
Do you have any idea how to fix that?

Thank you so much Aaron

@AaronJackson
Copy link
Owner

You should not be getting that error on line 45. Have you modified the code much?
There are two calls to system. The first is for the face alignment, which you seem to have fixed. The second is for the 3D reconstruction. This is the one you have not fixed. You have to add the line you added to the first call to system, to the second one as well. See if you can do it, if not, paste your copy of the run file and I will fix it for you.

@monabiyan
Copy link
Author

monabiyan commented Sep 10, 2017

yes, sorry, the line numbers changed a little bit since I commented out the previous system calls.
This error belongs to the first system call.

My first system call is :

retval = system(['cd face-alignment;' ...
                 '/Users/monabiyan/torch/install/bin/torch-activate; ' ...
                 'CUDA_VISIBLE_DEVICES=' num2str(gpunum) ...
                 ' th main.lua -model 2D-FAN-300W.t7' ...
                 ' -input ../' input_folder ...
                 ' -detectFaces true' ...
                 ' -mode generate' ...
                 ' -output ../' input_folder ...
                 ' -outputFormat txt  > /dev/null;']);

@AaronJackson
Copy link
Owner

You are missing a period and space before the path to torch-activate. It should be:

                 '. /Users/monabiyan/torch/install/bin/torch-activate; ' ...

or

                 'source /Users/monabiyan/torch/install/bin/torch-activate; ' ...

That should do it. Make sure you make a similar change to the other call to system.

@monabiyan
Copy link
Author

monabiyan commented Sep 10, 2017

It seems that my previous addressing was correct! Since with this new ones
'. /Users/monabiyan/torch/install/bin/torch-activate; ' ...
or
'source /Users/monabiyan/torch/install/bin/torch-activate; ' ...

I get more errors:

/bin/bash: source/Users/mohsennabian/torch/install/bin/torch-activate: No such file or directory
/bin/bash: th: command not found
Error using run (line 45)

same error with the 'dot' in the beginning.

@AaronJackson
Copy link
Owner

Please be very careful when copying and making changes. You are now missing a space after source.

@monabiyan
Copy link
Author

monabiyan commented Sep 10, 2017

Yes, Aaron, that was the space mistake.
Now it worked! Thank you so much.
I am getting the fb.python error though as the followings:

/Users/monabiyan/torch/install/bin/luajit: .../mohsennabian/torch/install/share/lua/5.1/trepl/init.lua:389: .../mohsennabian/torch/install/share/lua/5.1/trepl/init.lua:389: module 'fb.python' not found:No LuaRocks module found for fb.python
	no field package.preload['fb.python']
	no file '/Users/mohsennabian/.luarocks/share/lua/5.1/fb/python.lua'
	no file '/Users/mohsennabian/.luarocks/share/lua/5.1/fb/python/init.lua'
	no file '/Users/mohsennabian/torch/install/share/lua/5.1/fb/python.lua'
	no file '/Users/mohsennabian/torch/install/share/lua/5.1/fb/python/init.lua'
	no file './fb/python.lua'
	no file '/Users/mohsennabian/torch/install/share/luajit-2.1.0-beta1/fb/python.lua'
	no file '/usr/local/share/lua/5.1/fb/python.lua'
	no file '/usr/local/share/lua/5.1/fb/python/init.lua'
	no file '/Users/mohsennabian/.luarocks/lib/lua/5.1/fb/python.so'
	no file '/Users/mohsennabian/torch/install/lib/lua/5.1/fb/python.so'
	no file '/Users/mohsennabian/torch/install/lib/fb/python.dylib'
	no file './fb/python.so'
	no file '/usr/local/lib/lua/5.1/fb/python.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
	no file '/Users/mohsennabian/.luarocks/lib/lua/5.1/fb.so'
	no file '/Users/mohsennabian/torch/install/lib/lua/5.1/fb.so'
	no file '/Users/mohsennabian/torch/install/lib/fb.dylib'
	no file './fb.so'
	no file '/usr/local/lib/lua/5.1/fb.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
	[C]: in function 'error'
	.../mohsennabian/torch/install/share/lua/5.1/trepl/init.lua:389: in function 'require'
	main.lua:8: in main chunk
	[C]: in function 'dofile'
	...bian/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
	[C]: at 0x01001879f0
Error using run (line 45)
Failed to run Torch7 script.

So I guess I have to install fb.python as well, But do you have any source for installing it?

@AaronJackson
Copy link
Owner

Yes, first you need to install thpp. I recommend installing it from 1adrianb/thpp as it has some fixes for newer versions of Torch. Clone this repo and install with:

THPP_NOFB=1 ./build.sh

Then clone fblualib. Make sure you have glog, boost and python2.7 development packages installed. I haven't used a Mac for a few years but I think you can do this with MacPorts or Brew.

cd fblualib/fblualib/python/
luarocks make rockspec/*

@ghost
Copy link

ghost commented Sep 15, 2017

Had such a nightmare trying to install thpp and fb.python, so glad I found this! Might I recommend putting a link to it on the README page? It's a mess going through the different posts of different compiler errors. Really excited to try this out, looks super cool!

@AaronJackson
Copy link
Owner

@cpdurham Hey thanks! Will do.

@monabiyan
Copy link
Author

monabiyan commented Sep 15, 2017

@cpdurham were you able to install fb.python?

@monabiyan
Copy link
Author

monabiyan commented Sep 15, 2017

I tried many thing, didn't work. I finally found this :
https://github.com/facebook/fblualib/issues/2
the recommendation provided by 'vzhong' worked and I installed fb.python which uses docker software to do it.

But still running the MATLAB file, I got the same error:

/Users/monabiyan/torch/install/bin/luajit: .../mohsennabian/torch/install/share/lua/5.1/trepl/init.lua:389: .../mohsennabian/torch/install/share/lua/5.1/trepl/init.lua:389: module 'fb.python' not found:No LuaRocks module found for fb.python
	no field package.preload['fb.python']
	no file '/Users/mohsennabian/.luarocks/share/lua/5.1/fb/python.lua'
	no file '/Users/mohsennabian/.luarocks/share/lua/5.1/fb/python/init.lua'
	no file '/Users/mohsennabian/torch/install/share/lua/5.1/fb/python.lua'
	no file '/Users/mohsennabian/torch/install/share/lua/5.1/fb/python/init.lua'
	no file './fb/python.lua'
	no file '/Users/mohsennabian/torch/install/share/luajit-2.1.0-beta1/fb/python.lua'
	no file '/usr/local/share/lua/5.1/fb/python.lua'
	no file '/usr/local/share/lua/5.1/fb/python/init.lua'
	no file '/Users/mohsennabian/.luarocks/lib/lua/5.1/fb/python.so'
	no file '/Users/mohsennabian/torch/install/lib/lua/5.1/fb/python.so'
	no file '/Users/mohsennabian/torch/install/lib/fb/python.dylib'
	no file './fb/python.so'
	no file '/usr/local/lib/lua/5.1/fb/python.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
	no file '/Users/mohsennabian/.luarocks/lib/lua/5.1/fb.so'
	no file '/Users/mohsennabian/torch/install/lib/lua/5.1/fb.so'
	no file '/Users/mohsennabian/torch/install/lib/fb.dylib'
	no file './fb.so'
	no file '/usr/local/lib/lua/5.1/fb.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
	[C]: in function 'error'
	.../mohsennabian/torch/install/share/lua/5.1/trepl/init.lua:389: in function 'require'
	main.lua:8: in main chunk
	[C]: in function 'dofile'
	...bian/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
	[C]: at 0x01001879f0
Error using run (line 45)
Failed to run Torch7 script.

Please share your experience if you suceed.
Thanks

@AaronJackson
Copy link
Owner

Hi @monabiyan, I am beginning to wonder if this whole thing would be much easier if you were to find a Linux machine knocking around. Do you know if there is one available for you to use? Preferably with a GPU, but if not I can give you a CPU only version of the code/model.

@monabiyan
Copy link
Author

monabiyan commented Sep 15, 2017

@AaronJackson Yeah, you are right!
I think I will be able to find a Linux machine. I ll let you know if I couldn't find any with GPU.
Thank you so much

@AaronJackson
Copy link
Owner

@monabiyan Our group have a Mac which is shared but it has been used quite a bit recently so I haven't been able to get it running. When it becomes free, I will take a proper look and add some details to the readme file if I can get it working.

@monabiyan
Copy link
Author

@AaronJackson
Hope you are well. Just a quick question. To be able to run your code, I am ordering my school the requirements like Torch7 so they install it on the cluster machine of our university. It is Linux machine with GPU.
My question is that whether this "fblualib" is still required to be installed on Linux machine or not? Should I order that too?
If it is required, why didn't you mention it in the requirements?

Thank you so much

@ghost
Copy link

ghost commented Sep 20, 2017

@monabiyan
I can answer a bit, it's really not easy to get everything working and the "order" to install stuff is going to require some playing around with the person doing the installing as opposed to a simple checklist.

I followed this for dlib: https://www.learnopencv.com/install-dlib-on-ubuntu/, running matlab inside the workon environment.

I installed fblualib using that special fork of thpp for the compatibility with the current version of torch https://github.com/1adrianb/thpp. I recommend only installing fb-python https://github.com/facebook/fblualib/blob/master/fblualib/python/README.md. Avoid installing the entire library as that will fail with the thpp requirement, also requiring a metric ton of other bullshit (I tried this).

I did all of this and got it working on ubuntu 16.04. Also, just in case, octave did not work

edit: also some of the python code running through lua gave a seg fault (no message), I recommend just running the python code directly and see what messages crop up. One of them was because my fresh install didnt have python-tk (or matplotlib for that matter, doh), i think i did an apt-get install for python-tk, don't quite remember.

@imagine
Copy link

imagine commented Sep 20, 2017

I'd love to see this evolve into a Docker image. @AaronJackson is there anything particular that MatLab offers, or could it be ported to octave/scipy/numpy?

@AaronJackson
Copy link
Owner

AaronJackson commented Sep 20, 2017

I was actually playing with it in Octave today. From what I can tell there is a minor issue with the patch function. It always shows the edge vertices even when I set the colour to none. It's mostly compatible, if you fancy submitting a patch that doesn't break the MATLAB version (I can check this if you don't have MATLAB), I'll gladly accept a pull request.

Edit: and if that happens I'll try and build a docker image.
Another edit: just remembered that the isosurface function requires two arguments in octave. setting this to a value of 1 will work. Also, the lighting functions don't seem to exist but they can be disabled if octave. I found this https://www.gnu.org/software/octave/doc/v4.0.1/How-to-distinguish-between-Octave-and-Matlab_003f.html

@TomHeaven
Copy link

I tried to run the project on Mac OS with XCode 8 and gcc 6.2. However, I failed to compile and install fb.python. There would raise a lot of errors if compiling fb.python using clang++. Then I switched to gcc 6.2. However, there would be a linking error

[100%] Linking CXX shared module lib.so
Undefined symbols for architecture x86_64:
  "google::base::CheckOpMessageBuilder::NewString[abi:cxx11]()", referenced from:
      std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* google::MakeCheckOpString<int, int>(int const&, int const&, char const*) in Lib.cpp.o
ld: symbol(s) not found for architecture x86_64

It is quite frustrating. If any of u have successfully run this project on Mac OS. Please help!

@AaronJackson
Copy link
Owner

Unfortunately I am unable to offer any suggestions other than to use Linux, which is free. Install it to an external hard drive or something.

@TomHeaven
Copy link

I have figured that out. The solution is to compile fb.python using gcc-4.9. In terminal of Mac, type

brew install gcc@4.9

and add this

SET( CMAKE_CXX_COMPILER "/usr/local/bin/g++-4.9" )

to file fblualib/fblualib/python/CMakeLists.txt. At last, run

luarocks make rockspec/*

fb.python will be compiled with no problem. And this project will run on Mac OS X. :)

@hanazawarui10
Copy link

Hello, AaronJackson, thank you for your brilliant work. Could you please send me a CPU only version of code since I don't have a cuda supported GPU. I got the following error when I run the run.sh in Centos7:

/home/me/torch/install/bin/luajit: /home/me/torch/install/share/lua/5.1/torch/File.lua:343: unknown Torch class <torch.CudaTensor>
stack traceback:
[C]: in function 'error'

@AaronJackson
Copy link
Owner

There's isn't a CPU only version because the landmark detection network uses nngraph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants