Running lua ML model from Google Colab - lua

I am trying to run the AdaIN-style model in Google Colab. In order to do this, I need to install Lua. I saw this question and tried the solution given (reproduced below for convenience), both with the given distro and the official torch distro.
%cd /content/
!git clone https://github.com/nagadomi/distro.git torch --recursive
import os
os.chdir('./torch/')
!bash install-deps
!./install.sh
!. ./install/bin/torch-activate
Now it should work using absolute path to th:
!/content/torch/install/bin/th neural_style.lua -style_image examples/inputs/picasso_selfport1907.jpg -content_image examples/inputs/brad_pitt.jpg
However, the last line fails, giving me the below error
/bin/bash: . ./install/bin/torch-activate: No such file or directory
However, the binary for th seems to exist at the given filepath. Thus, I try to run the given command
th test.lua -content input/content/cornell.jpg -style input/style/woman_with_hat_matisse.jpg
but I get the following error
/content/torch/install/bin/luajit: /content/torch/install/share/lua/5.1/trepl/init.lua:389: module 'cudnn' not found:No LuaRocks module found for cudnn
I tried looking this up further, but wasn't able to make much progress.
I also tried this method, which seems similar to the above, but I get the same errors.
Any pointers would be appreciated.

Related

Trouble running openai gym environment on google colab

Error that I'm struggling with
I'm trying to use MarsExplorer (https://github.com/dimikout3/MarsExplorer) in google colab, but I'm struggling with properly importing it. I was able to successfully clone the repo, but when I try to run the demo mars_explorer isn't imported. How can I fix this?
Indeed #Dr.Snoopy makes a great point here. This is the line in test.py where it is expected to work:
from mars_explorer.envs.settings import DEFAULT_CONFIG as conf
Now, notice that this is being called from your runtime path, usually root in Colab's case (I suppose), then it should return an error.
Now, if installed, for instance with pip install -e you can both import the module and edit it as you go.
Check out these docs.-,6.1.2.%20The%20Module%20Search%20Path,-%C2%B6), they may be helpful to understand this error.
apply these two commands in colab cell:
!git clone https://github.com/dimikout3/GeneralExplorationPolicy.git
the above command will save GeneralExplorationPolicy folders in your colab and inside this folder you can find mars-explorer folder then make copy of the path of the mars-explorer folder for example. /content/GeneralExplorationPolicy/mars-explorer
then apply this command for install mars-explorer:
!pip install -e /content/GeneralExplorationPolicy/mars-explorer

pydrake is not available for installation anymore through google colab?

I have been using a google colab template for iterative LQR that uses the Pydrake, however, it seems like the code repository is removed and I can't reinstall it on google Colab:
try:
import pydrake
import underactuated
except ImportError:
!curl -s https://raw.githubusercontent.com/RussTedrake/underactuated/master/scripts/setup/jupyter_setup.py > jupyter_setup.py
from jupyter_setup import setup_underactuated
setup_underactuated()
# Setup matplotlib backend (to notebook, if possible, or inline).
from underactuated.jupyter import setup_matplotlib_backend
plt_is_interactive = setup_matplotlib_backend()
File "/content/jupyter_setup.py", line 1
404: Not Found
^
SyntaxError: invalid syntax
I tried clicking this link https://raw.githubusercontent.com/RussTedrake/underactuated/master/scripts/setup/jupyter_setup.py, and the page is not found... everything was working fine yesterday
Sorry. You're correct... I updated it this morning, and don't have a good deprecation policy in place on that repo, and this setup script is two versions ago. The path you want is https://raw.githubusercontent.com/RussTedrake/underactuated/master/setup/jupyter_setup.py
(remove the script from the directory). But if you look at that file, you'll see that even that is pointing to an updated setup script which you might want to point to.
This is actually all good news... we are on the path to a much better solution. You can now just pip install drake on colab (see the drake installation guide). Once I land the pip install underactuated (probably in time for my Spring offering of the class), then all of that nasty setup will be gone.

Problems with updating pfgplots inside docker with tds file structure

I have a docker image with texlive installed (via apt not tlmgr). I have a pgfplot in my project which needs a newer pgfplot version. I'm searching for ways to update my pgplots because I can't update it with tlmgr because of base install via apt.
Initial error message if I try to compile with texlive 2014:
! Package pgfkeys Error: Choice '1.16' unknown in choice key '/pgfplots/compat/
anchors'. I am going to ignore this key.
See the pgfkeys package documentation for explanation.
Type H <return> for immediate help.
...
l.7 \pgfplotsset{compat=1.16}
?
! Emergency stop.
...
l.7 \pgfplotsset{compat=1.16}
I downloaded the pgfplots.tds and did the following steps like the manual said:
docker cp pgfplots.tds docker_container_name:/root/texmf/pgfplots
export TEXINPUTS=/root/texmf/pgfplots/tex//:
export TEXDOCS=/root/texmf/pgfplots/doc//:
export LUAINPUTS=/root/texmf/pgfplots//:
texhash
Of course the export and texhash were done inside the container and not on the host system.
After this, the error message is gone, but I have a new issue:
package pgfplots notification 'compat/show suggested version=true': you might b
enefit from \pgfplotsset{compat=1.18} (current compat level: 1.16).
! Illegal parameter number in definition of \pgfmaththisrow#.
<to be read again>
I searched online and got the response that this is because of a broken pgfplots installation. In many articles the fix was just to install the texlive new. But I can't do that.
The issue should also not be in the tex code itself. If I install texlive on my host system, which is the most recent Ubuntu distro, the tex compiles just fine.
Can somebody help me in fixing this or lead me to a better way of upgrading pgfplots?
Resolution:
The pgfplots package 1.18.1 and also 1.16 were to recent. It had conflicts with the pgf package. I tried to go further back and landed on \pgfplotsset{1.14} and version 1.14 of pgfplots.tds.
This works fine now. I was probably pretty lucky that my plot looks and functions the same with this version as in 1.18.
This approach probably won't work for you if your more bound to version 1.18.

cv2.error: OpenCV(4.3.0) ../opencv_contrib/modules/dnn_superres/src/dnn_superres.cpp:97: error: (-2:Unspecified error) Model not specified

Im trying out this article;
https://towardsdatascience.com/deep-learning-based-super-resolution-with-opencv-4fd736678066
this is the code copied out of the article;
import cv2
from cv2 import dnn_superres
sr = dnn_superres.DnnSuperResImpl_create()
image = cv2.imread('./input.png')
path = "EDSR_x3.pb"
sr.readModel(path)
sr.setModel("edsr", 3)
result = sr.upsample(image)
cv2.imwrite("./upscaled.png", result)
i also tried opencv Super Resolution Tutorial;
https://docs.opencv.org/master/d5/d29/tutorial_dnn_superres_upscale_image_single.html
import cv2
from cv2 import dnn_superres
sr = dnn_superres.DnnSuperResImpl_create()
image = cv2.imread('./image.png')
path = "EDSR_x4.pb"
sr.readModel(path)
sr.setModel("edsr", 4)
result = sr.upsample(image)
cv2.imwrite("./upscaled.png", result)
My enviroment is anaconda3 opencv 4.3.0.
I either get the error from the title or i get "killed" when i run the opencv example.
*My file directory is all on the same level of the sample codes. I would just change my image file names.
I did try to compile opencv and opencv_contrib from cmake but, i didn't know how to have python refer to opencv and opencv_contrib from source.
ifollow this documentation to install opencv from source;
https://d*ocs.opencv.org/3.4/d2/de6/tutorial_py_setup_in_ubuntu.html
I opted to use anaconda wrapping of opencv 4.3.0 because i ran into too many dependency and wrongly installed package problems.
My friend from a meetup managed to apply the code from the article just as the article depicted while i tried to follow exactly what he did, using an anaconda enviorment. Would my problem stem from my virtual enviorment or opencv package version or the code itself? i did have another colleague run my code from my github branch and he had my exact same problems. How should i apprach the bugs im having and apply the super resolution examples i found?
The error 'Model not specified' comes from the fact that the Net is empty. You have to actually download the model and then provide the path to the 'sr.readModel()' function.
If you did that and it still does not work, you could try these two things:
Try a smaller image (in .png format).
Build OpenCV from source. Do not forget the contrib modules (this is where the dnn_superres module resides). You said you had a problem linking python. I would suggest to use this tutorial. After following that tutorial, do the following command (after you already did sudo make install), to link the python libraries:
sudo ldconfig

Compiling C extension with anaconda on Travis-CI missing __log_finite symbol

A C extension module that compiles fine on Travis-CI without anaconda fails when installed with anaconda. It appears to install just fine, but when I try to import it, I get the following error:
ImportError: /home/travis/anaconda/lib/python2.7/site-packages/quaternion/numpy_quaternion.so: undefined symbol: __log_finite
The full error can be seen here. Obviously, this looks like a linker error, where it can't find glibc (which I believe is where __log_finite is found). But why should it fail to find glibc?
When I run nm on that .so file (through Travis), it shows that __log_finite is indeed undefined, but shouldn't it find it through the usual process?
I've tried installing quaternion through pip and I've tried installing it by directly downloading it and running python setup.py install. Both seem to work, in the sense that it looks like all the files are where they should be. But both fail on import because they can't find that symbol.
I've even tried installing the full version of anaconda (rather than just miniconda, which is recommended). Nothing seems to work. How can I make Travis find that symbol, and is this something I'll have to worry about ordinarily with my distribution?
It appears to be a problem with a -ffast-math flag in my quaternion package. One thing that flag does is make the code assume that the numbers are finite, so that instead of using the log function, it uses some log_finite function, which for some reason Travis doesn't have --- or something. Anyway, I have my numba package set an environment variable in Travis builds, which the quaternion package then looks for on installation, and turns off fast-math. This is unfortunate, because it means I'm not actually testing the code as it's actually used. But it means my code builds and tests pass.
There seems to be about one mention of this on the internet. Or not; I can't tell.

Resources