From 43416c4717d2430c3e11f042294d12b781fee2e1 Mon Sep 17 00:00:00 2001 From: natanielruiz <nataniel777@hotmail.com> Date: 星期三, 27 九月 2017 04:09:30 +0800 Subject: [PATCH] Failed lstm experiment --- practice/smoothing_ypr.ipynb | 83 ++++++++++++++++++++++------------------- 1 files changed, 45 insertions(+), 38 deletions(-) diff --git a/practice/smoothing_ypr.ipynb b/practice/smoothing_ypr.ipynb index a411c30..408f91e 100644 --- a/practice/smoothing_ypr.ipynb +++ b/practice/smoothing_ypr.ipynb @@ -2,10 +2,8 @@ "cells": [ { "cell_type": "code", - "execution_count": 156, - "metadata": { - "collapsed": false - }, + "execution_count": 1, + "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", @@ -17,31 +15,27 @@ }, { "cell_type": "code", - "execution_count": 157, - "metadata": { - "collapsed": false - }, + "execution_count": 3, + "metadata": {}, "outputs": [], "source": [ "video_path = '../data/video/SGT036_2016_07_25_pivothead_AVI.avi'\n", "bbox_path = '../data/video/annotations/SGT036_childface.txt'\n", "\n", - "annot_path = '../output/video/output-SGT036_resnet18_cr_epoch_1.txt'\n", - "output_string = 'SGT036_resnet18_cr_epoch_1_flat_smoothed'" + "annot_path = '../output/video/output-SGT036_set4_normal_a1_epoch_25.txt'\n", + "output_string = 'SGT036_set4_normal_a1_epoch_25_smooth'" ] }, { "cell_type": "code", - "execution_count": 158, - "metadata": { - "collapsed": false - }, + "execution_count": 4, + "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[-6.069214 -0.831665 0.53318 ..., -3.836042 -3.868275 -2.377155]\n", + "[ 2.843239 6.065323 6.614468 ..., -0.936905 -1.396786 -3.20248 ]\n", "(8508,)\n", "(53464,)\n" ] @@ -93,10 +87,8 @@ }, { "cell_type": "code", - "execution_count": 159, - "metadata": { - "collapsed": false - }, + "execution_count": 5, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -107,31 +99,39 @@ } ], "source": [ - "window_len = 6\n", + "window_len = 3\n", "pad = window_len / 2\n", "window = 'flat'\n", + "window_2 = 'flat'\n", + "window_len_2 = 7\n", + "pad_2 = window_len_2 / 2\n", "\n", "s = np.r_[y[window_len-1:0:-1],y,y[-2:-window_len-1:-1]]\n", "t = np.r_[p[window_len-1:0:-1],p,p[-2:-window_len-1:-1]]\n", "u = np.r_[r[window_len-1:0:-1],r,r[-2:-window_len-1:-1]]\n", "\n", - "xa = np.r_[x_min_arr[window_len-1:0:-1],x_min_arr,x_min_arr[-2:-window_len-1:-1]]\n", - "xb = np.r_[x_max_arr[window_len-1:0:-1],x_max_arr,x_max_arr[-2:-window_len-1:-1]]\n", - "ya = np.r_[y_min_arr[window_len-1:0:-1],y_min_arr,y_min_arr[-2:-window_len-1:-1]]\n", - "yb = np.r_[y_max_arr[window_len-1:0:-1],y_max_arr,y_max_arr[-2:-window_len-1:-1]]\n", + "xa = np.r_[x_min_arr[window_len_2-1:0:-1],x_min_arr,x_min_arr[-2:-window_len_2-1:-1]]\n", + "xb = np.r_[x_max_arr[window_len_2-1:0:-1],x_max_arr,x_max_arr[-2:-window_len_2-1:-1]]\n", + "ya = np.r_[y_min_arr[window_len_2-1:0:-1],y_min_arr,y_min_arr[-2:-window_len_2-1:-1]]\n", + "yb = np.r_[y_max_arr[window_len_2-1:0:-1],y_max_arr,y_max_arr[-2:-window_len_2-1:-1]]\n", "\n", "if window == 'flat':\n", " w=np.ones(window_len, 'd')\n", "else:\n", " w=eval('np.' + window + '(window_len)')\n", + " \n", + "if window_2 == 'flat':\n", + " w_2=np.ones(window_len_2, 'd')\n", + "else:\n", + " w_2=eval('np.' + window_2 + '(window_len_2)') \n", "\n", "y = np.convolve(w / w.sum(), s, mode='valid')[pad:-pad]\n", "p = np.convolve(w / w.sum(), t, mode='valid')[pad:-pad]\n", "r = np.convolve(w / w.sum(), u, mode='valid')[pad:-pad]\n", - "x_min_arr = np.convolve(w / w.sum(), xa, mode='valid')[pad:-pad]\n", - "x_max_arr = np.convolve(w / w.sum(), xb, mode='valid')[pad:-pad]\n", - "y_min_arr = np.convolve(w / w.sum(), ya, mode='valid')[pad:-pad]\n", - "y_max_arr = np.convolve(w / w.sum(), yb, mode='valid')[pad:-pad]\n", + "x_min_arr = np.convolve(w_2 / w_2.sum(), xa, mode='valid')[pad_2:-pad_2]\n", + "x_max_arr = np.convolve(w_2 / w_2.sum(), xb, mode='valid')[pad_2:-pad_2]\n", + "y_min_arr = np.convolve(w_2 / w_2.sum(), ya, mode='valid')[pad_2:-pad_2]\n", + "y_max_arr = np.convolve(w_2 / w_2.sum(), yb, mode='valid')[pad_2:-pad_2]\n", "\n", "pose_dict = {}\n", "bbox_dict = {}\n", @@ -151,10 +151,8 @@ }, { "cell_type": "code", - "execution_count": 160, - "metadata": { - "collapsed": false - }, + "execution_count": 7, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -166,11 +164,20 @@ ], "source": [ "video = cv2.VideoCapture(video_path)\n", - "width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH)) # float\n", - "height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT)) # float\n", + "# New cv2\n", + "# width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH)) # float\n", + "# height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT)) # float\n", + "#\n", + "# # Define the codec and create VideoWriter object\n", + "# fourcc = cv2.VideoWriter_fourcc(*'MJPG')\n", + "# out = cv2.VideoWriter('output/video/output-%s.avi' % args.output_string, fourcc, 30.0, (width, height))\n", + "\n", + "# Old cv2\n", + "width = int(video.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)) # float\n", + "height = int(video.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)) # float\n", "\n", "# Define the codec and create VideoWriter object\n", - "fourcc = cv2.VideoWriter_fourcc(*'MJPG')\n", + "fourcc = cv2.cv.CV_FOURCC(*'MJPG')\n", "out = cv2.VideoWriter('../output/video/output-%s.avi' % output_string, fourcc, 30.0, (width, height))\n", "\n", "txt_out = open('../output/video/output-%s.txt' % output_string, 'w')\n", @@ -226,9 +233,9 @@ "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python [conda root]", + "display_name": "Python 2", "language": "python", - "name": "conda-root-py" + "name": "python2" }, "language_info": { "codemirror_mode": { @@ -240,7 +247,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.12" + "version": "2.7.13" } }, "nbformat": 4, -- Gitblit v1.8.0