PPB(PingPongBall) Depth Estimation을 진행하다가 발생한 문제이다.
Depth Estimation 방법으로 Geometrical Depth Estimation 방법을 사용하였는데 종방향거리 증가에 따라 오차가 발생했다. 따라서 적절한 보정이 필요했고, 급한대로 4개의 Point를 구해서 {(22.5, 35) (45, 71) (67.5, 112) (90, 150)} / {(23.0443) (44.0179) (67.9045) (90.0433)} 이를 보정하기 위한 함수를 적용하였다.
그 결과 값이 정밀하게 나왔다.
%tensorflow_version 2.x
import tensorflow.compat.v1 as tf
print(tf.__version__)
device_name = tf.test.gpu_device_name()
if device_name != '/device:GPU:0':
raise SystemError('GPU device not found')
else:
print('Find GPU at: {}'.format(device_name))
# 학습 데이터로 4개의 점을 준다.(22.5, 35.5), (45, 71), (67.5, 112), (90, 150)
x_train = [22.5, 45, 67.5, 90]
y_train = [35.5, 71, 112, 150]
# Weight, bias는 추정할 y = Wx + b의 기울기(Weight)와 절편 (bias)
W = tf.Variable(tf.random_normal([1]), name = 'weight')
b = tf.Variable(tf.random_normal([1]), name = 'bias')
# y = wx + b 라는 뜻
hypothesis = x_train * W + b
# 내가 추정한 값 - 실제값을 제곱해준 것 cost(비용)함수
# 추정값이 실제값과 같은것이 가장 이상적인 상황이므로 cost가 0으로 되는 과정이 필요하다.
cost = tf.reduce_mean(tf.square(hypothesis - y_train))
# 경사하강법 적용
optimizer = tf.train.GradientDescentOptimizer(learning_rate = 0.000001)
train = optimizer.minimize(cost)
session = tf.Session()
session.run(tf.global_variables_initializer())
# 10000번 반복으로 cost가 0이 되는 부분을 찾을 것.
# session.run(train): 학습 시작
# 결과값 출력 weight와 bias를 보겠다.
for i in range(1000000001):
session.run(train)
if i % 100 == 0:
print(i, session.run(cost), session.run(W), session.run(b))