LINCellularNeuroscience / VAME

Variational Animal Motion Embedding - A tool for time series embedding and clustering
GNU General Public License v3.0
176 stars 60 forks source link

Is it possible to run VAME on google colab? #47

Closed Virginia9733 closed 3 years ago

Virginia9733 commented 3 years ago

Hi,

I am currently trying to run VAME on my laptop without GPU. I could not create training data set as I mentioned in #46 I am wondering if it is possible to run VAME on google colab and use its GPU?

I tried to installed anaconda in colab and have successfully created the conda enviroment as followed:

from google.colab import drive drive.mount('/content/drive')

import os os.chdir("/content/drive/MyDrive/DeepLabCut_ROI/VAME")

!nvidia-smi

!wget https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh !bash Anaconda3-5.2.0-Linux-x86_64.sh -bfp /usr/local

import sys sys.path.insert(0, "/usr/local/lib/python3.7/site-packages/")

!conda env create -f VAME.yaml

!source activate VAME

However, when I tried to install vame on colab, I got the error message belowed: !python setup.py install

/usr/local/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type' warnings.warn(msg) running install running bdist_egg running egg_info writing vame.egg-info/PKG-INFO writing dependency_links to vame.egg-info/dependency_links.txt writing entry points to vame.egg-info/entry_points.txt writing requirements to vame.egg-info/requires.txt writing top-level names to vame.egg-info/top_level.txt reading manifest file 'vame.egg-info/SOURCES.txt' writing manifest file 'vame.egg-info/SOURCES.txt' installing library code to build/bdist.linux-x86_64/egg running install_lib running build_py creating build/bdist.linux-x86_64/egg creating build/bdist.linux-x86_64/egg/vame copying build/lib/vame/init.py -> build/bdist.linux-x86_64/egg/vame creating build/bdist.linux-x86_64/egg/vame/initialize_project copying build/lib/vame/initialize_project/new.py -> build/bdist.linux-x86_64/egg/vame/initialize_project copying build/lib/vame/initialize_project/init.py -> build/bdist.linux-x86_64/egg/vame/initialize_project creating build/bdist.linux-x86_64/egg/vame/util copying build/lib/vame/util/gif_pose_helper.py -> build/bdist.linux-x86_64/egg/vame/util copying build/lib/vame/util/csv_to_npy.py -> build/bdist.linux-x86_64/egg/vame/util copying build/lib/vame/util/init.py -> build/bdist.linux-x86_64/egg/vame/util copying build/lib/vame/util/align_egocentrical.py -> build/bdist.linux-x86_64/egg/vame/util copying build/lib/vame/util/auxiliary.py -> build/bdist.linux-x86_64/egg/vame/util creating build/bdist.linux-x86_64/egg/vame/model copying build/lib/vame/model/create_training.py -> build/bdist.linux-x86_64/egg/vame/model copying build/lib/vame/model/evaluate.py -> build/bdist.linux-x86_64/egg/vame/model copying build/lib/vame/model/dataloader.py -> build/bdist.linux-x86_64/egg/vame/model copying build/lib/vame/model/rnn_model.py -> build/bdist.linux-x86_64/egg/vame/model copying build/lib/vame/model/rnn_vae.py -> build/bdist.linux-x86_64/egg/vame/model copying build/lib/vame/model/init.py -> build/bdist.linux-x86_64/egg/vame/model creating build/bdist.linux-x86_64/egg/vame/analysis copying build/lib/vame/analysis/segment_behavior.py -> build/bdist.linux-x86_64/egg/vame/analysis copying build/lib/vame/analysis/tree_hierarchy.py -> build/bdist.linux-x86_64/egg/vame/analysis copying build/lib/vame/analysis/init.py -> build/bdist.linux-x86_64/egg/vame/analysis copying build/lib/vame/analysis/videowriter.py -> build/bdist.linux-x86_64/egg/vame/analysis copying build/lib/vame/analysis/umap_visualization.py -> build/bdist.linux-x86_64/egg/vame/analysis copying build/lib/vame/analysis/pose_segmentation.py -> build/bdist.linux-x86_64/egg/vame/analysis copying build/lib/vame/analysis/community_analysis.py -> build/bdist.linux-x86_64/egg/vame/analysis copying build/lib/vame/analysis/gif_creator.py -> build/bdist.linux-x86_64/egg/vame/analysis copying build/lib/vame/analysis/generative_functions.py -> build/bdist.linux-x86_64/egg/vame/analysis byte-compiling build/bdist.linux-x86_64/egg/vame/init.py to init.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/initialize_project/new.py to new.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/initialize_project/init.py to init.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/util/gif_pose_helper.py to gif_pose_helper.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/util/csv_to_npy.py to csv_to_npy.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/util/init.py to init.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/util/align_egocentrical.py to align_egocentrical.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/util/auxiliary.py to auxiliary.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/model/create_training.py to create_training.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/model/evaluate.py to evaluate.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/model/dataloader.py to dataloader.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/model/rnn_model.py to rnn_model.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/model/rnn_vae.py to rnn_vae.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/model/init.py to init.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/analysis/segment_behavior.py to segment_behavior.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/analysis/tree_hierarchy.py to tree_hierarchy.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/analysis/init.py to init.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/analysis/videowriter.py to videowriter.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/analysis/umap_visualization.py to umap_visualization.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/analysis/pose_segmentation.py to pose_segmentation.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/analysis/community_analysis.py to community_analysis.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/analysis/gif_creator.py to gif_creator.cpython-36.pyc byte-compiling build/bdist.linux-x86_64/egg/vame/analysis/generative_functions.py to generative_functions.cpython-36.pyc creating build/bdist.linux-x86_64/egg/EGG-INFO copying vame.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO copying vame.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO copying vame.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO copying vame.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO copying vame.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO copying vame.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO zip_safe flag not set; analyzing archive contents... creating 'dist/vame-1.0-py3.6.egg' and adding 'build/bdist.linux-x86_64/egg' to it removing 'build/bdist.linux-x86_64/egg' (and everything under it) Processing vame-1.0-py3.6.egg Copying vame-1.0-py3.6.egg to /usr/local/lib/python3.6/site-packages Adding vame 1.0 to easy-install.pth file Installing vame script to /usr/local/bin

Installed /usr/local/lib/python3.6/site-packages/vame-1.0-py3.6.egg Processing dependencies for vame==1.0 Searching for opencv-python Reading https://pypi.org/simple/opencv-python/ Downloading https://files.pythonhosted.org/packages/bb/08/9dbc183a3ac6baa95fabf749ddb531bd26256edfff5b6c2195eca26258e9/opencv-python-4.5.1.48.tar.gz#sha256=78a6db8467639383caedf1d111da3510a4ee1a0aacf2117821cae2ee8f92ce37 Best match: opencv-python 4.5.1.48 Processing opencv-python-4.5.1.48.tar.gz Writing /tmp/easy_install-9nd3ra8a/opencv-python-4.5.1.48/setup.cfg Running opencv-python-4.5.1.48/setup.py -q bdist_egg --dist-dir /tmp/easy_install-9nd3ra8a/opencv-python-4.5.1.48/egg-dist-tmp-loujmu5p Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/setuptools/sandbox.py", line 154, in save_modules yield saved File "/usr/local/lib/python3.6/site-packages/setuptools/sandbox.py", line 195, in setup_context yield File "/usr/local/lib/python3.6/site-packages/setuptools/sandbox.py", line 250, in run_setup _execfile(setup_script, ns) File "/usr/local/lib/python3.6/site-packages/setuptools/sandbox.py", line 45, in _execfile exec(code, globals, locals) File "/tmp/easy_install-9nd3ra8a/opencv-python-4.5.1.48/setup.py", line 10, in entry_points={"console_scripts": "vame = vame:main"}, ModuleNotFoundError: No module named 'skbuild'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "setup.py", line 29, in "opencv-python", File "/usr/local/lib/python3.6/site-packages/setuptools/init.py", line 129, in setup return distutils.core.setup(**attrs) File "/usr/local/lib/python3.6/distutils/core.py", line 148, in setup dist.run_commands() File "/usr/local/lib/python3.6/distutils/dist.py", line 955, in run_commands self.run_command(cmd) File "/usr/local/lib/python3.6/distutils/dist.py", line 974, in run_command cmd_obj.run() File "/usr/local/lib/python3.6/site-packages/setuptools/command/install.py", line 67, in run self.do_egg_install() File "/usr/local/lib/python3.6/site-packages/setuptools/command/install.py", line 117, in do_egg_install cmd.run() File "/usr/local/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 412, in run self.easy_install(spec, not self.no_deps) File "/usr/local/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 654, in easy_install return self.install_item(None, spec, tmpdir, deps, True) File "/usr/local/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 701, in install_item self.process_distribution(spec, dist, deps) File "/usr/local/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 746, in process_distribution [requirement], self.local_index, self.easy_install File "/usr/local/lib/python3.6/site-packages/pkg_resources/init.py", line 774, in resolve replace_conflicting=replace_conflicting File "/usr/local/lib/python3.6/site-packages/pkg_resources/init.py", line 1057, in best_match return self.obtain(req, installer) File "/usr/local/lib/python3.6/site-packages/pkg_resources/init.py", line 1069, in obtain return installer(requirement) File "/usr/local/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 673, in easy_install return self.install_item(spec, dist.location, tmpdir, deps) File "/usr/local/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 699, in install_item dists = self.install_eggs(spec, download, tmpdir) File "/usr/local/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 884, in install_eggs return self.build_and_install(setup_script, setup_base) File "/usr/local/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 1152, in build_and_install self.run_setup(setup_script, setup_base, args) File "/usr/local/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 1138, in run_setup run_setup(setup_script, args) File "/usr/local/lib/python3.6/site-packages/setuptools/sandbox.py", line 253, in run_setup raise File "/usr/local/lib/python3.6/contextlib.py", line 99, in exit self.gen.throw(type, value, traceback) File "/usr/local/lib/python3.6/site-packages/setuptools/sandbox.py", line 195, in setup_context yield File "/usr/local/lib/python3.6/contextlib.py", line 99, in exit self.gen.throw(type, value, traceback) File "/usr/local/lib/python3.6/site-packages/setuptools/sandbox.py", line 166, in save_modules saved_exc.resume() File "/usr/local/lib/python3.6/site-packages/setuptools/sandbox.py", line 141, in resume six.reraise(type, exc, self._tb) File "/usr/local/lib/python3.6/site-packages/setuptools/_vendor/six.py", line 685, in reraise raise value.with_traceback(tb) File "/usr/local/lib/python3.6/site-packages/setuptools/sandbox.py", line 154, in save_modules yield saved File "/usr/local/lib/python3.6/site-packages/setuptools/sandbox.py", line 195, in setup_context yield File "/usr/local/lib/python3.6/site-packages/setuptools/sandbox.py", line 250, in run_setup _execfile(setup_script, ns) File "/usr/local/lib/python3.6/site-packages/setuptools/sandbox.py", line 45, in _execfile exec(code, globals, locals) File "/tmp/easy_install-9nd3ra8a/opencv-python-4.5.1.48/setup.py", line 10, in entry_points={"console_scripts": "vame = vame:main"}, ModuleNotFoundError: No module named 'skbuild'

Virginia9733 commented 3 years ago

I have fixed this issue by using:

%%shell eval "$(conda shell.bash hook)" # copy conda command to shell conda activate VAME python

Now I could run the code in google colab, NVIDIA-SMI 465.19.01
Driver Version: 460.32.03
CUDA Version: 11.2
Anaconda: Anaconda3-2020.02-Linux-x86_64.sh python 3.7.10

Now I have successfully installed vame in the conda envirorment and could import vame. however, I faced the same issue as I mentioned in #46 , I could not create a training set.

Python 3.7.10 (default, Feb 26 2021, 18:47:35) [GCC 7.3.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information.

import vame Using CUDA GPU active: True GPU used: Tesla T4 config = vame.init_new_project(project='Muhang-VAME-Project', videos='/content/drive/MyDrive/VAME/video-1.mp4', working_directory='/content/drive/MyDrive/VAME/',videotype='.mp4') Created "/content/drive/MyDrive/VAME/Muhang-VAME-Project-May15-2021/videos" Created "/content/drive/MyDrive/VAME/Muhang-VAME-Project-May15-2021/data" Created "/content/drive/MyDrive/VAME/Muhang-VAME-Project-May15-2021/results" Created "/content/drive/MyDrive/VAME/Muhang-VAME-Project-May15-2021/model" No videos found in / Perhaps change the videotype, which is currently set to: .mp4 No videos found in / Perhaps change the videotype, which is currently set to: .mp4 No videos found in / Perhaps change the videotype, which is currently set to: .mp4 No videos found in / Perhaps change the videotype, which is currently set to: .mp4 No videos found in / Perhaps change the videotype, which is currently set to: .mp4 No videos found in . Perhaps change the videotype, which is currently set to: .mp4 Copying the videos

A VAME project has been created.

Now its time to prepare your data for VAME. The first step is to move your pose .csv file (e.g. DeepLabCut .csv) into the //YOUR//VAME//PROJECT//videos//pose_estimation folder. From here you can call either the function vame.egocentric_alignment() or if your data is by design egocentric call vame.csv_to_numpy(). This will prepare the data in .csv into the right format to start working with VAME.

config = '/content/drive/MyDrive/VAME/Muhang-VAME-Project-May15-2021/config.yaml' vame.update_config(config) ATTENTION! You are about to overwrite your current config.yaml. If you did changes, back up your current version and compare to the updated version. Do you want to continue? (yes/no)yes Your config.yaml has been updated. vame.egocentric_alignment(config, pose_ref_index=[0,5]) Your data is now ine right format and you can call vame.create_trainset() vame.create_trainset(config) Creating training dataset... Using robust setting to eliminate outliers! IQR factor: 4 Traceback (most recent call last): File "", line 1, in File "/content/drive/My Drive/VAME/VAME-master/vame/model/create_training.py", line 186, in create_trainset traindata(cfg, files, cfg['test_fraction'], cfg['num_features'], cfg['savgol_filter']) File "/content/drive/My Drive/VAME/VAME-master/vame/model/create_training.py", line 66, in traindata X = np.concatenate(X_train, axis=0) File "<__array_function__ internals>", line 6, in concatenate ValueError: need at least one array to concatenate

Virginia9733 commented 3 years ago

Sorry, I solved it, there is something wrong when I create the project, the video was not copied. Now it works almost perfectly.

Virginia9733 commented 3 years ago

I have another issue when running VAME on colab. I could run the vame.gif successfully on my local computer. However, when I tried to trun it on colab, I got this error message:

Python 3.7.10 (default, Feb 26 2021, 18:47:35) [GCC 7.3.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information.

import vame Using CUDA GPU active: True GPU used: Tesla T4 config = vame.init_new_project(project=project, videos=videos, working_directory=working_directory, videotype='.mp4') Traceback (most recent call last): File "", line 1, in NameError: name 'project' is not defined config = '/content/drive/MyDrive/VAME/Muhang-VAME-Project-May15-2021/config.yaml' vame.gif(config, pose_ref_index=[0,5], subtract_background=True, start=None, length=500, max_lag=30, label='community', file_format='.mp4', crop_size=(300,300)) Loading background image ... Can't find background image... Calculate background image... tcmalloc: large alloc 9107841024 bytes == 0x562fc25a6000 @ 0x7fcc516ff001 0x7fcc4f91704f 0x7fcc4f96ab57 0x7fcc4f96c9e7 0x7fcc4fa0ede8 0x562fb6b138b4 0x562fb6b139d1 0x562fb6b7fe5a 0x562fb6ac2d09 0x562fb6b13055 0x562fb6b7b466 0x562fb6ac2d09 0x562fb6b13055 0x562fb6b7b466 0x562fb6ac2d09 0x562fb6b130b7 0x562fb6b7c539 0x562fb6ac2d09 0x562fb6ac3be4 0x562fb6ac3c0c 0x562fb6bdaa74 0x562fb6aa2f8b 0x562fb6aa3141 0x562fb6aa31e1 0x562fb6aa3c7e 0x562fb6be622c 0x7fcc510dbbf7 0x562fb6b8ae90 Compute background image for video video-1: 100% 1000/1000 [01:01<00:00, 16.32it/s] Finishing up! tcmalloc: large alloc 9107841024 bytes == 0x5631e1d30000 @ 0x7fcc516fd1e7 0x7fcc4f916f6e 0x7fcc4f96ac57 0x7fcc4f96ad67 0x7fcc4f962e05 0x7fcc4fa0367b 0x562fb6b13956 0x562fb6b139d1 0x562fb6b8035a 0x562fb6ac2d09 0x562fb6ac401f 0x7fcc4f957b24 0x562fb6b13840 0x562fb6b139d1 0x562fb6b7f755 0x562fb6ac2d09 0x562fb6b130b7 0x562fb6b7c539 0x562fb6ac2d09 0x562fb6ac401f 0x562fb6b7ce97 0x562fb6ac2d09 0x562fb6b130b7 0x562fb6b7c539 0x562fb6ac2d09 0x562fb6ac3df5 0x7fcc4f957b24 0x562fb6b13840 0x562fb6b139d1 0x562fb6b7f755 0x562fb6ac2d09

CalledProcessError Traceback (most recent call last)

in () 1 ----> 2 get_ipython().run_cell_magic('shell', '', 'eval "$(conda shell.bash hook)" # copy conda command to shell\nconda activate VAME\npython ')

2 frames /usr/local/lib/python3.7/dist-packages/google/colab/_system_commands.py in check_returncode(self) 137 if self.returncode: 138 raise subprocess.CalledProcessError( --> 139 returncode=self.returncode, cmd=self.args, output=self.output) 140 141 def _reprpretty(self, p, cycle): # pylint:disable=unused-argument

CalledProcessError: Command 'eval "$(conda shell.bash hook)" # copy conda command to shell conda activate VAME python ' died with <Signals.SIGKILL: 9>.

pavolbauer commented 3 years ago

Hi, I can confirm that several users are running VAME on the google coud / via google colab. The last error you posted seems like there is a problem in the activation of the VAME environment, caused by a bash call carried out from python. Check out how conda environments can be installed and activated via colab, some usefull links might be: https://cloud.google.com/python/docs/setup https://stackoverflow.com/questions/53031430/conda-environment-in-google-colab-google-colaboratory/62346425 Best, Pavol

Virginia9733 commented 3 years ago

Many thank!!!