imitation learning 특성 상 optimal expert demonstration에 대해 imitation을 하는 경우가 대부분이었는데, 이와 다르게 diverse-quality demo가 주어졌을 때를 다룬 논문이다. 대부분 demonstration의 quality를 사전에 알고 있거나 알려주는 expert (confidence score, ranking score)가 등장하지만, 여기서는 quality와 reward를 variational approach로 활용하는 법을 논의한다. 

이 논문에서는 diversity를 noise-densities로 측정함에 따라 quality가 확률 그래프로 나타나게 된다. 또한 그냥 quality-estimation을 하면 에러가 누적될 수 있으므로 reward를 활용하여 expert's decision making의 의도를 부여하고자 하였고, importance sampling을 활용하여 데이터 활용도를 높였다. 

RL은 현실 세계에서 접하기 힘든 reward를 기반으로 한 알고리즘이라는 한계가 있고, imitation learning은 high-quality demo가 있어야만 제대로된 작동이 가능하다는 단점이 있다. 

v(k) 는 expert k의 분포, mu(s)는 초기 상태 분포, pi *는 optimal policy. p(us,a) 는 noise action 분포, 따라서 최종 p(tau k)는 trajectory probability density induced by pi 이다.

noise density p_n은 expert의 성능 비교도 하고, demo quality 비교도 할 수 있게함.

multi-modal policy는 different modality가 different policy를 측정한다. 근데 그건 여러 다른 expert들의 optimal policy를 측정하는 거라 quality가 다른 setting에서는 맞지 않는다. good modality를 찾기 위해서는 demo quality를 알아야하므로 세팅과 맞지 않다.

theta와 w는 regression method로 배울 수 있고 pi_theta는 optimal policy, p_w는 noise-density를 추측한다.  

지도학습에서 diverse-quality data를 다루는 법은 quality를 측정하는 건데, parameterized model p_{theta, w}를 이용해 p_d를 측정할 수 있다. 하지만 이 방법은 에러가 누적되는 것에 취약하고, regression은 train과 test 때의 data distribution이 같다는 것을 가정하는데, data distribution은 policy에 의존적이므로 imitation learning에서 train/ test distribution은 다를 수밖에 없다. 

# VILD: A robust method for diverse-quality demonstrations

(1) 먼저, noise-density와 reward function을 explicit하게 parameterized model 한다. 

(2) 그리고 variational approach로 그 parameter를 추측하고,

(3) RL을 활용하여 구현하고,

(4) importance sampling으로 data-efficiency를 높였다. 

------------------------------------------------------------------------------------------

(1) IRL로 reward를 구한다음에 RL로 policy를 찾으면 compounding error를 피할 수 있다. RL로 배우는 policy가 data distribution과 policy의 의존성을 고려하기 때문이다. (?) 따라서 이 논문은 maximum entropy IRL을 기반으로 p_d를 estimate하는데, 

Z_phi,w 는 normalization term으로 p_phi, w가 적분했을 때 1이 되도록 한다.

phi는 cumulative reward 가 joint probability density of actions given optimal policy에 비례하도록 한다. 

즉 optimal policy일 때 누적 reward가 커지는 것이다.

더보기

KL(A||B) = ∑ A log(A/B)

min KL(p_d || p_phi,w) =   min ∑ p_d (log Z+ log(∫pi* p_n / ∫e^r p_w) )

=max (E_pd [ ∑ log (∫e^l )] - log Z)

(하... 열심히 썼는데 윈도우 업데이트가 다 날렸다... 임시저장도 안되었나...)

(2) variational approach는 Jensen inequality와 variational distribution으로 integral에 lower-bound를 줄 수 있다는 것인데.. integral은 optimal variational distribution의 expectation으로 최적화가 가능해서 선호하고 그렇게 접근했지만, optimal variational distribution 구하는 것도 sub-optimal problem이라 어려웠다. 

어쨌든 결론은 F-G 를 위와 같이 특정 variational model q_psi와 q_theta를 이용하여 lower-bound를 줄 수 있다는 것이고, 그 lower-bound는 maximum entropy RL과 유사하게 해결할 수 있다는 것이다. 그럼으로써 F-G 최적화를 할 수 있다.

(3) RL로 density model 고르기.

(10)식을 최적화하기 위해서 아래와 같이 Gaussian distribution N으로 density model들을 꾸밀 수 있다. Covariance C가 클수록 low-expertise demo이고 작을수록 high-expertise라고 볼 수 있다. 

저렇게 density 모델을 잡고 최적화를 하면 (13) 식으로 나타낼 수 있고, minimize L w.r.t. theta는 transition probability tilda(p_s)와 reward r_phi에 대해 maximum entropy를 푸는것과 같기 때문에 RL로 풀 수 있다. 

'Ubuntu and setups' 카테고리의 다른 글

RLLab Setup & Miniconda setup  (0) 2022.10.20
ubuntu vim setup, git rebase 관련  (0) 2022.02.22
ubuntu user 만들기  (0) 2021.07.31
git config temporal username  (0) 2021.07.14
mount disk in ubuntu + conda pip errors  (0) 2021.07.05

https://stackoverflow.com/questions/9619199/best-way-to-preserve-numpy-arrays-on-disk

 

 

best way to preserve numpy arrays on disk

I am looking for a fast way to preserve large numpy arrays. I want to save them to the disk in a binary format, then read them back into memory relatively fastly. cPickle is not fast enough,

stackoverflow.com

https://discuss.pytorch.org/t/how-to-speed-up-the-data-loader/13740

 

 

How to speed up the data loader

Hi I want to know how to speed up the dataloader. I am using torch.utils.data.DataLoader(8 workers) to train resnet18 on my own dataset. My environment is Ubuntu 16.04, 3 * Titan Xp, SSD 1T. Epoch: [1079][0/232] Time 5.149 (5.149) Data 5.056 (5.056) Loss 0

discuss.pytorch.org

 

npy/npz 나 hdf5로 저장하는 것이 제일 numpy 저장할 때 좋다. 

NVIDIA DALI 는 data augmentation에 유용하다는데 augmentation을 안할 때에도 유용한지, image data랑 다른 종류 데이터가 섞여있어도 속도가 빠른 건지를 확인해봐야 할듯.

각 저장 형식마다 속도 및 용량 비교한 것은 아래 github에서 확인 가능!

https://github.com/epignatelli/array_storage_benchmark

'Experiments' 카테고리의 다른 글

Latex 자주 쓰는 모음 정리  (2) 2021.12.18
learning rate 결정하기  (0) 2021.08.11
image encoder batch normalization  (0) 2021.08.01
python pickle errors (stable-baselines3 trained agent)  (0) 2021.07.11
ResNet & iResNet  (0) 2021.02.11

https://medium.com/gumgum-tech/handling-class-imbalance-by-introducing-sample-weighting-in-the-loss-function-3bdebd8203b4

 

Handling Class Imbalance by Introducing Sample Weighting in the Loss Function

“Nobody is Perfect” This quote not just applies to us humans but also the data that surrounds us. Any data science practitioner needs to…

medium.com

적은 sample class에는 큰 loss weight를 주고, 많은 sample class에는 작은 loss weight를 준다?!

https://discuss.pytorch.org/t/why-different-validation-and-train-loss-for-the-same-data/60487/3

 

Why different validation and train loss for the same data

Hi @ptrblck I am not using any dropout layers. The architecture I am using can be seen below: ResNet3D( (strConv1): Conv3d(64, 64, kernel_size=(3, 3, 3), stride=(2, 2, 2), padding=(1, 1, 1)) (strConv2): Conv3d(128, 128, kernel_size=(3, 3, 3), stride=(2, 2,

discuss.pytorch.org

test loss가 train loss에 비해 월등히 높은 현상이 일어남. (둘의 dataset이 같은데도.) - batchnormalization eval 했더니 해결되었다.

 

batch size가 작아서라는 의견도,

data가 non-stationary 해서 그렇다는 의견도( momentum을 줄이면 된다고 하는데) 있고,

batch norm이 eval에서는 batch statistics를 train 때의 평균을 가지고 하는데 뭐 그게 잘 안맞을 때 이런 현상이 있다는 얘기도 있다. (track_running_stats=False)

https://discuss.pytorch.org/t/model-eval-gives-incorrect-loss-for-model-with-batchnorm-layers/7561/38

 

Model.eval() gives incorrect loss for model with batchnorm layers

Its pretty huge. with net.train(): 7e-8 with net.eval(): 99.3 Here is the truncated output (btw i fixed a bug in the original repro code, where the input batchsize did not match the output batchsize, now batchone = torch.ones[2, 1, 64, 64]… instead of [4

discuss.pytorch.org

https://github.com/pytorch/pytorch/issues/4741

 

Using model.eval() with batchnorm gives high error · Issue #4741 · pytorch/pytorch

I tested my network using model.eval() on one testing element and the result was very high. I tried to do testing using the same minibatch size as the training and also testing on one batch size wi...

github.com

 

'Experiments' 카테고리의 다른 글

learning rate 결정하기  (0) 2021.08.11
data loader 속도 높이기  (0) 2021.08.09
python pickle errors (stable-baselines3 trained agent)  (0) 2021.07.11
ResNet & iResNet  (0) 2021.02.11
Imitating Latent Policy from Observation 2  (0) 2020.12.26
sudo adduser newuser
sudo usermod -aG sudo newuser

1. anaconda 설치

https://hskalena.github.io/installment/RLlab-ExperimentSetup/

2. mujoco 설치

3. git 파일들 받기

 

'Ubuntu and setups' 카테고리의 다른 글

ubuntu vim setup, git rebase 관련  (0) 2022.02.22
ubuntu disk usage by user  (0) 2021.08.11
git config temporal username  (0) 2021.07.14
mount disk in ubuntu + conda pip errors  (0) 2021.07.05
210504 NVIDIA CUDA installation  (0) 2021.05.04

1. 그래프 상에서 future desired return을 넣어주고 stitching을 할수 있게 하였다. 

supervised learning을 하는 것과 유사. 

2. GPT architecture를쓰는데, longer context가 더 잘한다. (long term credit assignment)

3. sparse reward setting에서도 잘 하는가? improve robustness  - assumption of density of reward.

 

Lex Fridman이 인터뷰한 Sergey levine 이  RL = Learning based control 이라고 정의했다. 

Decision Transformer -> model-free offline RL

Trajectory Transformer -> model-based offline RL

Inverse dynamics는 inverse problem이다.

inverse rigid body dynamics인 경우도 있고, inverse structural dynamics인 경우도 있다.

inverse rigid-body dynamics는 body kinematics (motion)과 body's inertial properties(질량과 moment of inertia - 관성 모멘트) 기반으로 forces, moments of force(torque)를 계산하는 것이다. 

사람의 관절과 로봇 관절을 표현하기 위해 link-segment model을 이용하여 interconnected segment의 행동을 분석한다. inverse dynamics는 여러 파트의 knematics가 주어졌을 때 각 움직임의 minimum forces and moment를 계산한다. 

--> inverse dynamics는 특정 가정하에 외부 힘(ex. ground reaction forces 지면반발력)과 관절 움직임을 측정한 것으로부터 internal moments and forces를 계산하는 것이다. 

 

# Applications

robotics와 biomechanics에서 많이 이용한다.

Robotics에서는 현재 task의 robots' end-point move에서 필요한 힘(torque)를 계산할 때 쓴다. 

로봇이 특정 움직임을 취하려면 각 motor가 알맞은 electric current를 적정 시각에 공급받아야한다.

따라서 motor가 어떻게 움직이는 것을 알면 robot arm motion도 예측해낼 수 있고, 그걸 forward dynamics problem이라고 한다.

처음 Bayo가 접근한 방법은 링크 하나짜리 로봇에 frequency-domain method (주파수 영역방식)를 적용하는 것이었는데, 이건 non-causal exact solution이다. 그 이유는 right-half plane zeros in the hub-torque-to-tip transfer function 때문이라는데.. 이걸 nonlinear multi-flexible-link에 적용시키는 것이 중요하다. control group과 같이 passive joint control로 하면 굉장히 안정적인 tip-tracking control을 구사할 수 있게된다.

 

 

https://stackoverflow.com/questions/22058041/commit-without-setting-user-email-and-user-name/32794854

 

Commit without setting user.email and user.name

I try to commit like this git commit --author='Paul Draper <my@email.org>' -m 'My commit message' but I get *** Please tell me who you are. Run git config --global user.email "you@examp...</my@email.org>

stackoverflow.com

git -c user.name='Paul Draper' -c user.email='my@email.org' commit -m '...'

이 방식대로 commit 했을 경우, pull, push 등 할때마다 -c 를 붙여줘야하기 때문에, 사실 alias를 등록해놓는것이 낫다.

'Ubuntu and setups' 카테고리의 다른 글

ubuntu disk usage by user  (0) 2021.08.11
ubuntu user 만들기  (0) 2021.07.31
mount disk in ubuntu + conda pip errors  (0) 2021.07.05
210504 NVIDIA CUDA installation  (0) 2021.05.04
vncserver setting, ssh 터널링 등  (0) 2021.01.25

https://www.youtube.com/watch?v=5jeVWOLW1bE

--> 잘 설명해놓은 유튜브 링크!

# Abstract

보라색이 먼저 실행되면서 L_psi를 구하고, 파란색으로 parameter 학습을 한다. 그리고 초록색으로 image+S로 gripper도 예측하고, 마지막으로 action도 예측함. 초록색에선 BC loss를 활용한다.

# Preliminaries

MAML (model-agnostic meta-learning algorithm)을 발전시킨 알고리즘. 한 개의 human demo만 봐도 따라가능.

1. domain shift btw provided data and evaluation setting

2. learn without labels (human's actions)

 

(1) Meta-learning: the ability to learn new tasks quickly and efficiently을 기르자. 

여러 meta-training tasks로 학습하고 새로운 meta-test tasks로 검증하기.

meta-learning은 학습과 추론 모두 특정 p(T) 분포에서 sample 되는 task라고 가정한다.

optimize deep network's initial parameter setting = 대충 몇번의 gradient descent on a few datapoints 만으로도 충분히 effective generalization을 할 수 있게. (few-shot generalization)

learning a prior over functions and fine-tuning process as inference under the learned prior.

theta: model parameter(initialization), D: labeld data, task T, phi: updated parameters, alpha: stepsize

inner loss: adaptation objective, outer objective: meta-objective

실제로는 multiple inner gradient step을 자주 사용한다.

MAML은 one-shot imitation learning인데, teleoperation을 통해 모은 robot demo로 mean-squared error behavioral cloning을 수행했다. 하지만 이것은 raw video of human 이나 domain shift를 해결할 수 없기 때문에 이 논문에서는 그걸 해결할 예정.

 

#4 Learning from humans

 

A. Problem overview

사람 video로부터 배운다는 것은 inference problem이라 볼 수 있는데, 한번의 사람 데모만 보고 prior knowledge를 알아내서 robot policy parameter phi를 그 task에 맞게 추론하는 것.

사람 video 한번 보고 알려면 1. rich prior encapsulating visual and physical understanding of world, 2. 사람은 어느 종류의 결과를 선호하는지 3. 어떤 action이 로봇이 그것을 할 수 있게 하는지. 를 알고있어야한다.

--> pre-defined vision system, pre-determined set of human objectives, known dynamics model을 manual encoding 할수는 있지만 task-specific 하고 시간이 들고, data로부터 benefit을 얻지 못한다.

human은 observation만 제공, robot은 image, state, action을 제공한다. arm appearance, background clutter, camera viewpoint 변화가 있을 수 있는데, 아직 아무 가정도 하지 않음.

 

B. Domain-adaptive meta-learning

D_tr는 task T에 대해 하나의 사람 데모만을 가지고, D_val은 task T에 대해 여럿 robot demo를 가진다. 

D_tr로 inner adaptation objective 계산할 때 human action을 몰라서 standard imitation learning loss를 못쓴다.

그래서 action이 필요없는 adaptation objective을 배우기로 했고, policy activation 때만 쓰기로 했다. 그렇게 하면서도 policy parameter를 업뎃하기 위한 gradient를 생산할 수 있고, gradient update 후엔 effective action을 생산할 수 있다.

meta-training에서 robot action을 가지고 supervise를 하기때문에 아예 불가능한 얘기가 아니다. 

adaptation loss는 directing policy parameter update - policy가 제대로 된 visual cue를 보도록하여 제대로 된 action을 도출하도록 한다.  --> psi가 adaptation objective

 

new task에 대해 policy parameter 추론할 때 1개의 human demo와 배운 loss L_psi로부터 theta를 위한 gradient descent를 이용한다.

policy_phi에 대해 BC objective
inner gradient descent adaptation이랑 합쳐서 놨을때 meta-training objective

human policy가 phi인거고 psi가 로봇 policy 인듯!

meta-objective를 optimize하는 알고리즘

 

meta-test time 때 human으로부터 배우는 알고리즘.

C. Learned Temporal Adaptation objectives

 

human video에서 관련 정보들(의도, task-relevant objects)을 빼오는게 adaptation objective이다. 

adaptation objective는 true action에 대한 정보 없이도 괜찮은 gradient info를 policy에 제공해야한다는 점에서 어렵다.

learned loss는 policy에 perceptual component를 바꿔서 맞는 object에 집중하도록 gradient를 제공한다. 그런데 어떤 behavior를 따라해야하고, 어떤 object가 관련있는지알기 위해서는 몇개의 frame을 봐야한다. 

--> 이런 temporal information을 얻기위해 learned adaptation objective는 multiple time steps를 couple하고 multiple time step동안의 policy activation을 활용한다.

temporal convolution이 temporal, sequential data에 효율적이므로 adaptation objective L_psi는 multiple layers of 1D convolutions over time - 이게 traditional recurrent NN like LSTM보다 parameter efficient하고 더 간단하다. 

MAML에서는 two-head architecture를 썼었는데, one head는 pre-update demonstration을 위해 쓰였고 the other은 post-update policy를 위한 것이었다. 이거는 특정 timestep에서 policy network의 마지막 hidden layer에 작용하는 learned linear loss function으로도 해석될 수 있다. loss and the gradient는 demo에서 모든 timestep을 평균내는 방식으로 계산되고. 이런 simple averaging은 temporal info를 담기에 효과적이지 않을 것이라서 다른 방식으로 temporal loss를 구했고 그건 single-timestep linear loss보다 좋다.

 

D. probabilistic interpretation

learned adaptation objective와 meta-learning을 한다는 것은 framework of probabilistic graphical model을 활용한다는 것과 같다. MAML도 approximately inferring a posterior over policy parameters phi given the evidence D_tr = d_h and a prior over the parameters given by theta

phi = theta에서 시작해서 likelihood (1)에 gradient descent를 주는것은 MAP(maximum a posteriori) inference를 (2)에 주는 것과 같다. (theta는 weights에 Gaussian prior를 주는데 평균 theta이고 covariance는 step size와 gradient step의 개수에 의존적이다.) 

log p(D^{tr}_T | \phi) ---(1)
log p(\phi | D^{tr}_T, \theta) ---(2)

adaptation 은 learned loss인 L_psi (phi, D_tr)에 대해 gradient descent 하는거지, likelihood (1)에 하는게 아니다. 그리고 Gaussian prior log p(phi | theta)를 사용하기에 아래와 같은 joint distribution에 MAP inference를 하는것.

partially directed factor graph with learned factor psi over phi and D_tr has log-energy L_psi

Bayesian inference는 phi를 통합하는게 필요하지만, MAP inference는 tractable alternative를 제공한다. 

https://stackoverflow.com/questions/63329657/python-3-7-error-unsupported-pickle-protocol-5

 

Python 3.7 Error: Unsupported Pickle Protocol 5

I'm trying to restore a pickled config file from RLLib (json didn't work as shown in this post), and getting the following error: config = pickle.load(open(f"{path}/params.pkl", "rb&...

stackoverflow.com

pip install --upgrade --quiet cloudpickle pickle5 라고만 치면 3.7 환경에서도 cloudpickle 5를 쓸 수 있다.

'Experiments' 카테고리의 다른 글

data loader 속도 높이기  (0) 2021.08.09
image encoder batch normalization  (0) 2021.08.01
ResNet & iResNet  (0) 2021.02.11
Imitating Latent Policy from Observation 2  (0) 2020.12.26
Imitating Latent Policy from Observation  (0) 2020.12.11

+ Recent posts