Code Monkey home page Code Monkey logo

smalr_online's Introduction

SMALR

This repository provides the annotation tool and the fitting code that fits the SMAL model to a set of images with annotated 2D keypoints and silhouettes and performs refinement as described in the SMALR paper: Lions and Tigers and Bears: Capturing Non-Rigid, 3D, Articulated Shape from Images, by Silvia Zuffi, Angjoo Kanazawa, and Michael J. Black, CVPR 2018. teaser

If you are looking for the 3D results from the SMALR paper, please find them in the project page.

This was also used for making the training data for SMALST.

We provide a demo for applying the code to images of the Tasmanian tiger, the Grevy's zebra, and cheetah.

The code was written by Silvia Zuffi and Angjoo Kanazawa, with contributions from Matt Loper, Federica Bogo, Javier Romero, Gerard Pons Moll.

Installation

The code requires python 3.8 and the following packages: chumpy, opencv, matplotlib, numpy, opendr, mesh library (https://github.com/MPI-IS/mesh), SMPL (https://smpl.is.tue.mpg.de/), Eigen (http://eigen.tuxfamily.org/index.php?title=Main_Page#Download)

You can follow this procedure:

python3 -m venv venv_smalr_online
source venv_smalr_online/bin/activate
pip3 install chumpy
pip3 install opencv-python
pip3 install matplotlib
pip3 install opendr
pip3 install sklearn

You need to do the following changes to opendr: In venv_smalr_online/lib/python3.8/site-packages/opendr/common.py change line 467 adding cast to int as (int(verts_by_face.shape[0]/f.shape[1]). In venv_smalr_online/lib/python3.8/site-packages/opendr/renderer.py search for dImage_wrt_2dVerts and add a cast to int as int(self.v.r.size/3). In venv_smalr_online/lib/python3.8/site-packages/opendr/camera.py at line 102 add the cast to int as int(self.v.r.size*2/3).

Install the mesh library following the instructions in https://github.com/MPI-IS/mesh.

Download Eigen, you do not need to compile it.

You need to compile the code in the directory src/smalr/sbody/alignment/mesh_distance. To do this go to the directory:

cd src/smalr/sbody/alignment/mesh_distance

Edit the file setup.py to set EIGEN_DIR to the location of Eigen. Then type:

make

Place the directory smpl_webuser from SMPL in the src/smalr directory. Note that to use python3 you need to load the pickle file with:

dd = pickle.load(open(fname_or_dict, "rb"), encoding='latin1')

Settings are listed in smalr_settings.py.

Running the Demo

Run python run_on_animals.py.

You will obtain images like the ones below:

demo demo demo demo

In the settings file, there is an option max_tex_weight that if set to True gives sharp texture, and if set to False gives smooth texture. We used smooth texture for the Tasmanian tiger in the SMALR paper and shape texture for making the dataset of Grevy's zebra in the SMALST paper. demo demo

We also provide a couple of examples with cheetahs, using only one image. demo

Annotation Tool

This repo also contains the annotation tool in Matlab we used to annotate the keypoints in src/annotate_kp_matlab. The driver is annotate_images.m. Please look at the README file in the annotation tool directory for more details.

Citation

If you found any of the pieces of code useful in this repo, please cite the following papers:

@inproceedings{Zuffi:CVPR:2018,  
  title = {Lions and Tigers and Bears: Capturing Non-Rigid, {3D}, Articulated Shape from Images},  
  author = {Zuffi, Silvia and Kanazawa, Angjoo and Black, Michael J.},  
  booktitle = {IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},  
  pages = {3955--3963},  
  publisher = {IEEE Computer Society},  
  year = {2018}. 
}

@inproceedings{Zuffi:CVPR:2017,  
  title = {{3D} Menagerie: Modeling the {3D} Shape and Pose of Animals},  
  author = {Zuffi, Silvia and Kanazawa, Angjoo and Jacobs, David and Black, Michael J.},  
  booktitle = {IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},  
  pages = {5524--5532},  
  publisher = {IEEE Computer Society},  
  year = {2017},  
}

Related Work

If you are interested in this line of work, you may also find this SMALify repo from Ben Biggs useful!

smalr_online's People

Contributors

michaeljblack avatar silviazuffi 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

smalr_online's Issues

Align SMAL model to new 3D scan.

Hi, may I ask for how to align SMAL model to a new 3D scan?
We already got the CT high-resolution scan. The code for the original SMAL model is not provided.
Therefore, I tried to fit the scan with the SMAL model based on Flame (https://github.com/Rubikplayer/flame-fitting). I follow the code of FLAME and use a similar objective function ( scan-to-mesh distance, landmarks distance, pose penalty, shape penalty with similar weights). I defined 54 points (from head to tail) on both the SMAL model and our CT scan using MeshLab as FLAME. However, the result of fitting SMAL to a scan based on FLAME code is very poor.
To eliminate the possibility that the SMAL model did not cover rodents, I also try to fit the Bear mesh provided in the result part of this SMALR project. It is also not working.
Could you please give me some advice on it? Is it possible to share the code about how to build a SMAL model based on scan?

Evaluation process takes too long

Dear Silvia,

I would like to ask you how long the process of generating texture from a single image on a GPU machine took for you. For me, it takes 5-7 minutes and I was wondering if it is normal.

Best regards
Ruslan

Hardcoded path in io.py

Thanks for releasing your code! Just a small note, load_keymapping() in mycore/io.py, map_path is a hardcoded path and I think should be changed to

map_path = '../../src/annotate_kp_matlab/ferrari2smpl_%s.mat' % animal

Fitting SMAL to other animals & getting the parameters

Thank you for the code for python3.x!!

I hope to fit the SMAL model to some animal RGB. Could I fit the model into other animals' (e.g. cows') pictures? How should I do it?

After fitting, could I save *.ply or *.obj files with the parameters (shape and pose) of the fitting results? How to get them?

Error as running run_on_animals.py

Hello, I have the problem shown in follow, I think I followed by the instructions of README completely. I have no idea how to fix it, could u please give me some hints? BTW, I have got a figure of key points of test image.

1
Scaling images of: 0.75
1
Scaling images of: 0.75
1
Scaling images of: 0.75
1
Scaling images of: 0.75
1
Scaling images of: 0.75
/home/lisicheng/smalr/src/smalr/mycore/io.py:58: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
v_ids = np.array([np.atleast_1d(v) - 1 for v in v_ids])
2.13e+04 | cam: 2.13e+04 | cam_t: 0.00e+00
Traceback (most recent call last):
File "/home/lisicheng/smalr/src/smalr/run_on_animals.py", line 96, in
compute_clips(family, model_name, shape_data_name, base_dirs, save_base_dir,
File "/home/lisicheng/smalr/src/smalr/compute_clips.py", line 326, in compute_clips
bodys = compute_multiple_unsynch_frames_from_annotations(bodys, bodys_imgs, model,
File "/home/lisicheng/smalr/src/smalr/compute_clips.py", line 99, in compute_multiple_unsynch_frames_from_annotations
model, keypoints[ic], key_vids[ic], _, landmarks[ic], landmarks_names[ic] = get_annotation(
File "/home/lisicheng/smalr/src/smalr/track_frame_fit.py", line 77, in get_annotation
rot, trans = estimate_global_pose(landmarks, keypoint_vids, model, cam, img, viz=viz)
File "/home/lisicheng/smalr/src/smalr/estimate_global_pose.py", line 146, in estimate_global_pose
ch.minimize( obj, x0=free_variables, method='dogleg', callback=on_step, options={'maxiter': 100, 'e_3': .0001})
File "/home/lisicheng/anaconda3/envs/smalr/lib/python3.8/site-packages/chumpy/optimization.py", line 41, in minimize
return minimize_dogleg(fun, free_variables=x0, on_step=callback, **options)
File "/home/lisicheng/anaconda3/envs/smalr/lib/python3.8/site-packages/chumpy/optimization_internal.py", line 408, in minimize_dogleg
state.updateJ(obj)
File "/home/lisicheng/anaconda3/envs/smalr/lib/python3.8/site-packages/chumpy/optimization_internal.py", line 304, in updateJ
self.J = obj.J
File "/home/lisicheng/anaconda3/envs/smalr/lib/python3.8/site-packages/chumpy/optimization_internal.py", line 105, in J
result = self.dr_wrt(self.x, profiler=self.profiler).copy()
File "/home/lisicheng/anaconda3/envs/smalr/lib/python3.8/site-packages/chumpy/optimization_internal.py", line 50, in dr_wrt
new_jac = self.obj.dr_wrt(freevar, profiler=profiler)
File "/home/lisicheng/anaconda3/envs/smalr/lib/python3.8/site-packages/chumpy/ch.py", line 772, in dr_wrt
dr2 = p.dr_wrt(wrt, profiler=profiler)
File "/home/lisicheng/anaconda3/envs/smalr/lib/python3.8/site-packages/chumpy/ch.py", line 772, in dr_wrt
dr2 = p.dr_wrt(wrt, profiler=profiler)
File "/home/lisicheng/anaconda3/envs/smalr/lib/python3.8/site-packages/chumpy/ch.py", line 772, in dr_wrt
dr2 = p.dr_wrt(wrt, profiler=profiler)
[Previous line repeated 1 more time]
File "/home/lisicheng/anaconda3/envs/smalr/lib/python3.8/site-packages/chumpy/ch.py", line 775, in dr_wrt
indirect_dr = self.compute_rop(p, rhs=dr2)
File "/home/lisicheng/anaconda3/envs/smalr/lib/python3.8/site-packages/chumpy/ch.py", line 724, in compute_rop
dr = self._compute_dr_wrt_sliced(wrt)
File "/home/lisicheng/anaconda3/envs/smalr/lib/python3.8/site-packages/chumpy/ch.py", line 289, in _compute_dr_wrt_sliced
result = self.compute_dr_wrt(wrt)
File "/home/lisicheng/anaconda3/envs/smalr/lib/python3.8/site-packages/opendr-0.77-py3.8-linux-x86_64.egg/opendr/camera.py", line 104, in compute_dr_wrt
result = sp.csc_matrix((data, (IS, JS)))
File "/home/lisicheng/anaconda3/envs/smalr/lib/python3.8/site-packages/scipy/sparse/compressed.py", line 54, in init
other = self.class(coo_matrix(arg1, shape=shape,
File "/home/lisicheng/anaconda3/envs/smalr/lib/python3.8/site-packages/scipy/sparse/coo.py", line 147, in init
raise ValueError('cannot infer dimensions from zero '
ValueError: cannot infer dimensions from zero sized index arrays

Process finished with exit code 1

Stuck when trying run_on_animals.py demo.

Hi, I am trying to run the demo code but I got this output and it stuck there like forever:

Iteration 3
shape_w 6000.0
9.49e+07 | cam_t_pos_0: 0.00e+00 | feq_0: 9.47e+02 | fpos_0: 0.00e+00 | kp_proj_0: 5.59e+07 | pose_limit_0: 4.72e+05 | pose_prior_0: 3.52e+07 | pose_prior_tail_0: 3.52e+05 | shape_prior_0: 1.13e+06 | trans_init_0: 1.80e+06
9.48e+07 | cam_t_pos_0: 0.00e+00 | feq_0: 9.44e+02 | fpos_0: 0.00e+00 | kp_proj_0: 5.48e+07 | pose_limit_0: 4.54e+05 | pose_prior_0: 3.58e+07 | pose_prior_tail_0: 3.58e+05 | shape_prior_0: 1.58e+06 | trans_init_0: 1.80e+06
beta here: -0.23, -0.43, -0.01, -0.54, -0.33, 0.14, 0.01, -0.17, 0.03, -0.07, -0.15, 0.08, 0.10, -0.00, -0.28, 0.14, -0.01, 0.20, -0.07, -0.03,
Scale 6
weights: s2m 2000.00 m2s 10000.00
nan | cam_t_pos_0: 0.00e+00 | feq_0: 9.44e+02 | fpos_0: 0.00e+00 | kp_proj_0: 5.48e+07 | m2s_0: nan | pose_limit_0: 4.54e+05 | pose_prior_0: 3.58e+07 | pose_prior_tail_0: 3.58e+05 | s2m_0: 1.88e+06 | shape_prior_0: 1.58e+06 | trans_init_0: 1.80e+06

Would you please give me a hint on what I am struggling of and how to get through it ?
I think I have followed all the instructions given in README.md.

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.