HOME
  Security
   Software
    Hardware
  
FPGA
  CPU
   Android
    Raspberry Pi
  
nLite
  Xcode
   etc.
    ALL
  
LINK
BACK
 

[NEW] 2022/11/27

NVIDIA Jetsonで matching-with-gansを動かす方法 NVIDIA Jetsonで matching-with-gansを動かす方法

(Jetson Xavier NXの JetPack 5.0.1に matching-with-gansをインストールする!)

Tags: [Raspberry Pi], [電子工作], [ディープラーニング]




● Jetson Nano、Jetson Xavier NXの便利スクリプト

2020/07/03
【2020年版】NVIDIA Jetson Nano、Jetson Xavier NXの便利スクリプト
【2020年版】NVIDIA Jetson Nano、Jetson Xavier NXの便利スクリプト

  Jetsonの面倒な初期設定やミドルウェアのインストールを bashスクリプトの実行だけで簡単にできます


● NVIDIA Jetsonで matching-with-gansを動かす方法

Matching in GAN-Space

 Jetson Xavier NXの JetPack 5.0.1に matching-with-gansをインストールする!

 TensorFlowが必要なので下記の手順でインストールします。

[NEW] 2022/11/27
NVIDIA Jetson JetPack 5.0.1に TensorFlowを NVIDIA公式の手順でインストールする方法
NVIDIA Jetson JetPack 5.0.1に TensorFlowを NVIDIA公式の手順でインストールする方法

  Jetson Xavier NXの JetPack 5.0.1に TensorFlowをインストールする!

● Jetson Xavier NXの JetPack 5.0.1に matching-with-gansをインストールする方法

# Install Matching in GAN-Space
cd
git clone https://github.com/csinva/matching-with-gans --depth 1
cd matching-with-gans

cat requirements.txt
nano requirements.txt

tensorflow==1.14.0
↓
tensorflow>=1.14.0, <2.0

#   Building wheel for dlib (setup.py) ... error
#   error: subprocess-exited-with-error
#      ERROR: CMake must be installed to build dlib
sudo apt install -y cmake
# Setting up cmake (3.16.3-1ubuntu1.20.04.1) ...

pip install -r requirements.txt
  Building wheel for dlib (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [7 lines of output]
      running bdist_wheel
      running build
      running build_py
      running build_ext

      ERROR: CMake must be installed to build dlib

      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for dlib
$ python -V
Python 3.8.10

$ pip -V
pip 22.3.1 from /home/jetson/.local/lib/python3.8/site-packages/pip (python 3.8)

$ python3 -V
Python 3.8.10

$ pip3 -V
pip 22.3.1 from /home/jetson/.local/lib/python3.8/site-packages/pip (python 3.8)
$ pip freeze
absl-py==1.3.0
aiohttp==3.8.3
aiosignal==1.3.1
apt-clone==0.2.1
apturl==0.5.2
astor==0.8.1
astunparse==1.6.3
async-timeout==4.0.2
attrs==22.1.0
bcrypt==3.1.7
blinker==1.4
Brlapi==0.7.0
certifi==2019.11.28
chardet==3.0.4
charset-normalizer==2.1.1
Click==7.0
colorama==0.4.3
cryptography==2.8
cupshelpers==1.0
cycler==0.10.0
Cython==0.29.32
dbus-python==1.2.16
decorator==4.4.2
defer==1.0.6
distro==1.4.0
distro-info===0.23ubuntu1
dlib==19.24.0
duplicity==0.8.12.0
emoji==2.2.0
entrypoints==0.3
face-recognition==1.3.0
face-recognition-models==0.3.0
fasteners==0.14.1
ffmpeg-python==0.2.0
filelock==3.8.0
frozenlist==1.3.3
future==0.18.2
gast==0.3.3
google-pasta==0.2.0
graphsurgeon==0.4.6
grpcio==1.51.1
h5py==2.10.0
httplib2==0.14.0
huggingface-hub==0.11.1
idna==2.8
importlib-metadata==5.1.0
Jetson.GPIO==2.0.20
joblib==1.2.0
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.2
keyring==18.0.1
kiwisolver==1.0.1
language-selector==0.1
launchpadlib==1.10.13
lazr.restfulclient==0.14.2
lazr.uri==1.0.3
lockfile==0.12.2
louis==3.12.0
macaroonbakery==1.3.1
Mako==1.1.0
Markdown==3.4.1
MarkupSafe==2.1.1
matplotlib==3.1.2
min-dalle==0.4.11
mock==3.0.5
monotonic==1.5
more-itertools==9.0.0
multidict==6.0.2
numpy==1.23.5
oauthlib==3.1.0
olefile==0.46
onboard==1.4.1
opencv-python==4.6.0.66
opt-einsum==3.3.0
packaging==21.3
PAM==0.4.2
pandas==0.25.3
paramiko==2.6.0
pbr==5.11.0
pexpect==4.6.0
Pillow==9.3.0
pkgconfig==1.5.5
protobuf==3.19.6
pybind11==2.10.1
pycairo==1.16.2
pycrypto==2.6.1
pycups==1.9.73
PyGObject==3.36.0
PyICU==2.4.2
PyJWT==1.7.1
pymacaroons==0.13.0
PyNaCl==1.3.0
pyparsing==2.4.6
pyRFC3339==1.1
python-apt==2.0.0+ubuntu0.20.4.7
python-dateutil==2.7.3
python-dbusmock==0.19
python-debian===0.1.36ubuntu1
pytz==2019.3
pyxdg==0.26
PyYAML==5.3.1
regex==2022.10.31
requests==2.28.1
requests-unixsocket==0.2.0
scikit-learn==1.1.3
scipy==1.5.4
SecretStorage==2.3.1
semantic-version==2.10.0
setuptools-rust==1.5.2
simplejson==3.16.0
six==1.14.0
systemd-python==234
tensorboard==1.15.0
tensorflow==1.15.5+nv22.11
tensorflow-estimator==1.15.1
tensorrt==8.4.1.5
termcolor==2.1.1
testresources==2.0.1
threadpoolctl==3.1.0
tokenizers==0.13.2
torch @ https://developer.download.nvidia.com/compute/redist/jp/v502/pytorch/torch-1.13.0a0+936e9305.nv22.11-cp38-cp38-linux_aarch64.whl
tqdm==4.64.1
transformers==4.24.0
typing_extensions==4.4.0
ubuntu-advantage-tools==27.8
ubuntu-drivers-common==0.0.0
uff==0.6.9
urllib3==1.25.8
urwid==2.0.1
wadllib==1.3.3
Werkzeug==2.2.2
whisper==1.0
wrapt==1.14.1
xkit==0.0.0
yarl==1.8.1
zipp==3.11.0


● project_and_manipulate.sh
cd
cd matching-with-gans
cd projection_manipulation
./project_and_manipulate.sh

$ ls -l samples/*
-rw-rw-r-- 1 jetson jetson 215436 Dec  7 08:27 samples/chandan.jpg
-rw-rw-r-- 1 jetson jetson 188494 Dec  7 08:27 samples/pietro.jpg

samples/aligned:
-rw-rw-r-- 1 jetson jetson 1205779 Dec  9 21:40 chandan_01.png
-rw-rw-r-- 1 jetson jetson  889955 Dec  9 21:40 pietro_01.png

samples/interpolated:
-rw-rw-r-- 1 jetson jetson  812939 Dec  9 22:32 grid_chandan_01-pietro_01.png
-rw-rw-r-- 1 jetson jetson  500243 Dec  9 22:32 mean_chandan_01-pietro_01.png
-rw-rw-r-- 1 jetson jetson 2574199 Dec  7 08:27 pietro_01_chandan_01.png

samples/manipulated:
-rw-rw-r-- 1 jetson jetson 6446412 Dec  9 22:29 chandan_01.png
-rw-rw-r-- 1 jetson jetson 4911213 Dec  9 22:29 pietro_01.png

samples/projected:
-rw-rw-r-- 1 jetson jetson   36992 Dec  9 22:05 chandan_01.npy
-rw-rw-r-- 1 jetson jetson 1301216 Dec  9 22:05 chandan_01.png
-rw-rw-r-- 1 jetson jetson   36992 Dec  9 22:25 pietro_01.npy
-rw-rw-r-- 1 jetson jetson  946052 Dec  9 22:25 pietro_01.png

・chandan.jpg
chandan.jpg


・pietro.jpg
pietro.jpg



● aligned
・aligned_chandan_01.jpg
aligned_chandan_01.jpg


・aligned_pietro_01.jpg
aligned_pietro_01.jpg



● projected
・projected_chandan_01.jpg
projected_chandan_01.jpg


・projected_pietro_01.jpg
projected_pietro_01.jpg



● manipulated
・manipulated_chandan_01.jpg
manipulated_chandan_01.jpg


・manipulated_pietro_01.jpg
manipulated_pietro_01.jpg



● interpolated
・interpolated_pietro_01_chandan_01.jpg
interpolated_pietro_01_chandan_01.jpg
 pietro_01_chandan_01.jpgは元々 Gitに含まれている。

・interpolated_grid_chandan_01-pietro_01.jpg
interpolated_grid_chandan_01-pietro_01.jpg


・interpolated_mean_chandan_01-pietro_01.jpg
interpolated_mean_chandan_01-pietro_01.jpg




tensorflow.python.framework.errors_impl.NotFoundError: /home/jetson/matching-with-gans/lib/stylegan2/dnnlib/tflib/_cudacache/fused_bias_act_4c553492fe6ac8d457dc3f5f894d3780.so: undefined symbol: _ZN10tensorflow8internal21CheckOpMessageBuilder9NewStringEv

nano lib/stylegan2/dnnlib/tflib/custom_ops.py

dnnlib/tflib/custom_ops.py
compile_opts += ' --compiler-options \'-fPIC -D_GLIBCXX_USE_CXX11_ABI=0\''
↓
compile_opts += ' --compiler-options \'-fPIC -D_GLIBCXX_USE_CXX11_ABI=1\''
ModuleNotFoundError: No module named 'imageio'
pip3 install imageio
# Successfully installed imageio-2.22.4
ModuleNotFoundError: No module named 'seaborn'
pip3 install seaborn
# Successfully installed seaborn-0.12.1
ImportError: /home/jetson/.local/lib/python3.8/site-packages/sklearn/__check_build/../../scikit_learn.libs/libgomp-d22c30c5.so.1.0.0: cannot allocate memory in static TLS block
___________________________________________________________________________
Contents of /home/jetson/.local/lib/python3.8/site-packages/sklearn/__check_build:
_check_build.cpython-38-aarch64-linux-gnu.so__pycache__               setup.py
__init__.py
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.

If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.

$ ls -l /home/jetson/.local/lib/python3.8/site-packages/sklearn/__check_build/../../scikit_learn.libs/libgomp-d22c30c5.so.1.0.0
-rwxrwxr-x 1 jetson jetson 274664 Dec  7 09:03 /home/jetson/.local/lib/python3.8/site-packages/sklearn/__check_build/../../scikit_learn.libs/libgomp-d22c30c5.so.1.0.0

export LD_PRELOAD=/home/jetson/.local/lib/python3.8/site-packages/sklearn/__check_build/../../scikit_learn.libs/libgomp-d22c30c5.so.1.0.0
ModuleNotFoundError: No module named 'sklearn.linear_model.ridge'

pip3 freeze | grep sklearn
(none)

# 2019/07/30
pip3 install scikit-learn==0.21.3
# Successfully installed scikit-learn-0.21.3

袋有料なのでこれに入れてもらえますか?の写真素材
交際したばかりの彼女と初デートの写真素材
彼女「こっちへおいでよ!」の写真素材
ひとくちチョコッと食べる?の写真素材
cd
cd matching-with-gans
cd projection_manipulation

mkdir original_dir
cd original_dir
wget https://www.pakutaso.com/shared/img/thumb/yuukicyan0I9A4338.jpg
wget https://www.pakutaso.com/shared/img/thumb/takebeIMGL3521.jpg
wget https://www.pakutaso.com/shared/img/thumb/Tsurutama_MKT6495.jpg
wget https://www.pakutaso.com/shared/img/thumb/YUKA151206135839.jpg
cd ..

ls -l original_dir
各スクリプトの出力ディレクトリは自動的に作られる

ls -l original_dir

python3 ./scripts/00_align_images.py original_dir aligned_dir

ls -l aligned_dir

python3 ./scripts/01_project_images.py aligned_dir projected_dir

ls -l projected_dir

MPLBACKEND=Agg python3 ./scripts/02_manipulate.py projected_dir manipulated_dir ACHGMBSEW

ls -l manipulated_dir

MPLBACKEND=Agg python3 ./scripts/02_interpolate.py projected_dir interpolated_dir

ls -l interpolated_dir

● aligned
・aligned_takebeimgl3521_01.jpg
aligned_takebeimgl3521_01.jpg


・aligned_tsurutama_mkt6495_01.jpg
aligned_tsurutama_mkt6495_01.jpg


・aligned_yuka151206135839_01.jpg
aligned_yuka151206135839_01.jpg


・aligned_yuukicyan0i9a4338_01.jpg
aligned_yuukicyan0i9a4338_01.jpg



● projected
・projected_takebeimgl3521_01.jpg
projected_takebeimgl3521_01.jpg


・projected_tsurutama_mkt6495_01.jpg
projected_tsurutama_mkt6495_01.jpg


・projected_yuka151206135839_01.jpg
projected_yuka151206135839_01.jpg


・projected_yuukicyan0i9a4338_01.jpg
projected_yuukicyan0i9a4338_01.jpg



● manipulated
・manipulated_takebeimgl3521_01.jpg
manipulated_takebeimgl3521_01.jpg


・manipulated_tsurutama_mkt6495_01.jpg
manipulated_tsurutama_mkt6495_01.jpg


・manipulated_yuka151206135839_01.jpg
manipulated_yuka151206135839_01.jpg


・manipulated_yuukicyan0i9a4338_01.jpg
manipulated_yuukicyan0i9a4338_01.jpg



# regularize_mean_deviation_weightのデフォルトは 0.1
# parser.add_argument('--regularize_mean_deviation_weight', type=float, default=0.1,
#                         help='Penalize different w vectors to be the same')
python3 ./scripts/01_project_images.py aligned_dir projected_dir --regularize_mean_deviation_weight 0.1
cd matching-with-gans/
python3 ./scripts/02_interpolate.py projected_dir interpolated_dir

2022-12-10 00:33:11.533550: W tensorflow/core/framework/op_kernel.cc:1651] OP_REQUIRES failed at conv_grad_input_ops.cc:1067 : Resource exhausted: OOM when allocating tensor with shape[1,352,1025,1025] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/tensorflow_core/python/client/session.py", line 1365, in _do_call
    return fn(*args)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow_core/python/client/session.py", line 1349, in _run_fn
    return self._call_tf_sessionrun(options, feed_dict, fetch_list,
  File "/usr/local/lib/python3.8/dist-packages/tensorflow_core/python/client/session.py", line 1441, in _call_tf_sessionrun
    return tf_session.TF_SessionRun_wrapper(self._session, options, feed_dict,
tensorflow.python.framework.errors_impl.ResourceExhaustedError: 2 root error(s) found.
  (0) Resource exhausted: OOM when allocating tensor with shape[1,352,1025,1025] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
         [[{{node G_synthesis_1/_Run/G_synthesis/1024x1024/Conv0_up/conv2d_transpose}}]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.

         [[G_synthesis_1/_Run/saturate_cast/_1451]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.

  (1) Resource exhausted: OOM when allocating tensor with shape[1,352,1025,1025] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
         [[{{node G_synthesis_1/_Run/G_synthesis/1024x1024/Conv0_up/conv2d_transpose}}]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.

0 successful operations.
0 derived errors ignored.

$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7.3Gi       1.1Gi       5.3Gi       2.0Mi       893Mi       6.0Gi
Swap:         3.7Gi       129Mi       3.5Gi
sudo reboot

free -h
              total        used        free      shared  buff/cache   available
Mem:          7.3Gi       293Mi       6.6Gi        18Mi       454Mi       6.9Gi
Swap:         3.7Gi          0B       3.7Gi

systemctl --user stop pulseaudio.socket
systemctl --user stop pulseaudio.service

sudo systemctl stop docker
# Warning: Stopping docker.service, but it can still be activated by:
#   docker.socket
sudo systemctl stop docker.socket
sudo systemctl stop containerd.service
sudo systemctl stop gdm
sudo systemctl stop polkit

free -h
              total        used        free      shared  buff/cache   available
Mem:          7.3Gi       226Mi       6.7Gi        17Mi       454Mi       6.9Gi
Swap:         3.7Gi          0B       3.7Gi

cd matching-with-gans/
python3 ./scripts/02_interpolate.py projected_dir interpolated_dir
02_interpolate.pyはメモリ不足で動きません
ModuleNotFoundError: No module named 'keras'

pip3 install keras
Successfully installed keras-2.11.0
AttributeError: module 'tensorflow._api.v1.compat.v2' has no attribute '__internal__'

# 2020/06/25
pip3 install keras==2.4.3
# Successfully installed keras-2.4.3
ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`

# 2019/10/08
pip install keras==2.3.1
# Successfully installed keras-2.3.1
OK with TensorFlow 1.15
$ python3 ./scripts/01_project_images.py
2022-12-08 09:26:58.717141: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
WARNING:tensorflow:Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them.
usage: 01_project_images.py [-h] [--tmp-dir TMP_DIR] [--network-pkl NETWORK_PKL] [--vgg16-pkl VGG16_PKL] [--num-steps NUM_STEPS] [--initial-learning-rate INITIAL_LEARNING_RATE]
                            [--initial-noise-factor INITIAL_NOISE_FACTOR] [--verbose VERBOSE] [--video VIDEO] [--video-mode VIDEO_MODE] [--video-size VIDEO_SIZE] [--video-fps VIDEO_FPS]
                            [--video-codec VIDEO_CODEC] [--video-bitrate VIDEO_BITRATE] [--start_num START_NUM] [--end_num END_NUM] [--gpu GPU]
                            [--regularize_mean_deviation_weight REGULARIZE_MEAN_DEVIATION_WEIGHT]
                            src_dir dst_dir
01_project_images.py: error: the following arguments are required: src_dir, dst_dir
MPLBACKEND=Agg python3 ./projection_manipulation/scripts/02_interpolate_grid.py projected_dir interpolated_dir

ModuleNotFoundError: No module named 'projection_manipulation'

cd projection_manipulation
MPLBACKEND=Agg python3 ./scripts/02_interpolate_grid.py ../projected_dir ../interpolated_dir
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused

(02_manipulate.py:4880): Gdk-CRITICAL **: 09:14:09.193: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed

MPLBACKEND=Agg python3 script.py

MPLBACKEND=Agg python3 ./scripts/02_manipulate.py aligned_dir manipulated_dir ACHGMBSEW

import matplotlib
matplotlib.use('Agg')

● more free memory
$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7.3Gi       342Mi       6.4Gi        18Mi       572Mi       6.8Gi
Swap:         3.7Gi          0B       3.7Gi

systemctl --user stop pulseaudio.socket
systemctl --user stop pulseaudio.service

$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7.3Gi       339Mi       6.4Gi        18Mi       573Mi       6.8Gi
Swap:         3.7Gi          0B       3.7Gi

sudo systemctl stop docker
Warning: Stopping docker.service, but it can still be activated by:
  docker.socket

$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7.3Gi       309Mi       6.5Gi        18Mi       573Mi       6.8Gi
Swap:         3.7Gi          0B       3.7Gi

sudo systemctl stop docker.socket

$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7.3Gi       301Mi       6.5Gi        18Mi       573Mi       6.8Gi
Swap:         3.7Gi          0B       3.7Gi

$ sudo systemctl stop containerd.service

$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7.3Gi       275Mi       6.5Gi        18Mi       573Mi       6.9Gi
Swap:         3.7Gi          0B       3.7Gi

$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7.3Gi       275Mi       6.5Gi        18Mi       573Mi       6.9Gi
Swap:         3.7Gi          0B       3.7Gi
systemctl --user stop pulseaudio.socket
systemctl --user stop pulseaudio.service

sudo systemctl stop docker
# Warning: Stopping docker.service, but it can still be activated by:
#   docker.socket
sudo systemctl stop docker.socket
sudo systemctl stop containerd.service

# GNOME Online Accounts Daemon goa-daemon
apt rdepends gnome-online-accounts

GNOME Allow or disallow online accounts


sudo apt purge --auto-remove gnome-online-accounts

sudo apt purge --auto-remove tracker tracker-extract tracker-miner-fs

sudo systemctl stop gdm

sudo systemctl stop polkit

sudo service whoopsie stop
sudo apt-get purge --auto-remove whoopsie

$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7.3Gi       229Mi       6.7Gi        17Mi       452Mi       6.9Gi
Swap:         3.7Gi          0B       3.7Gi



Tags: [Raspberry Pi], [電子工作], [ディープラーニング]



[HOME] | [BACK]
リンクフリー(連絡不要、ただしトップページ以外は Web構成の変更で移動する場合があります)
Copyright (c) 2022 FREE WING,Y.Sakamoto
Powered by 猫屋敷工房 & HTML Generator

http://www.neko.ne.jp/~freewing/raspberry_pi/nvidia_jetson_install_matching_with_gans/