Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified to use dnn module of opencv instead caffe #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added images/5v6c18.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Cdr3qUqW8AE6LPu.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ChIXyPCW4AA_Rda.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/IMG_20180316_104132.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Pia-Cattapan_Plyaboy_(08B).jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 26 additions & 17 deletions predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
# OpenPose Position to 3D Position
# ----------------------------------------------

import cv2
import cv2 as cv
import sys
import numpy as np
import pandas as pd
import os
import caffe
import argparse
import h5py
import matplotlib.pyplot as plt
import matplotlib.animation as animation

import plaidml.keras
plaidml.keras.install_backend()

from mpl_toolkits.mplot3d import Axes3D
from keras.models import load_model

Expand All @@ -20,9 +23,9 @@
# ----------------------------------------------

MODEL_HDF5 = "3d-pose-baseline.hdf5"
IMAGE_PATH = "images/running.jpg"
CAFFE_MODEL = 'pose_iter_440000.caffemodel'
PROTOTXT = 'pose_deploy.prototxt'
#IMAGE_PATH = "images/running.jpg"
#CAFFE_MODEL = 'pose_iter_440000.caffemodel'
#PROTOTXT = 'pose_deploy.prototxt'

# ----------------------------------------------
# Input Data
Expand All @@ -37,14 +40,21 @@
IMAGE_WIDTH = int(sys.argv[3])
IMAGE_HEIGHT = int(sys.argv[4])

if not os.path.exists(IMAGE_PATH):
print(IMAGE_PATH+" not found")
parser = argparse.ArgumentParser()
parser.add_argument('--input', type=str, default='images/running.jpg')
parser.add_argument('--width', type=int, default=368)
parser.add_argument('--height', type=int, default=368)
parser.add_argument('--proto', type=str, default='pose_deploy.prototxt')
parser.add_argument('--model', type=str, default='pose_iter_440000.caffemodel')
args = parser.parse_args()

if not os.path.exists(args.input):
print(args.input + " not found")
sys.exit(1)

print IMAGE_PATH
input_img = cv2.imread(IMAGE_PATH)
input_img = cv.imread(args.input)

img = cv2.resize(input_img, (IMAGE_WIDTH, IMAGE_HEIGHT))
img = cv.resize(input_img, (args.width, args.height))

img = img[...,::-1] #BGR 2 RGB

Expand All @@ -53,13 +63,12 @@

data = data / 255.0

net = caffe.Net(PROTOTXT, CAFFE_MODEL, caffe.TEST)
net = cv.dnn.readNetFromCaffe(args.proto, args.model) #caffe.Net(PROTOTXT, CAFFE_MODEL, caffe.TEST)
data = data.transpose((0, 3, 1, 2))
out = net.forward_all(data = data)

paf = out[net.outputs[0]]
confidence = out[net.outputs[1]]
net.setInput(data)
out = net.forward()

confidence = out
# ----------------------------------------------
# Display output
# ----------------------------------------------
Expand All @@ -69,11 +78,11 @@

for i in range(confidence.shape[1]):
probMap = confidence[0, i, :, :]
minVal, prob, minLoc, point = cv2.minMaxLoc(probMap)
minVal, prob, minLoc, point = cv.minMaxLoc(probMap)

x = (input_img.shape[1] * point[0]) / confidence.shape[3]
y = (input_img.shape[0] * point[1]) / confidence.shape[2]

if prob > threshold :
points.append(x)
points.append(y)
Expand Down
5 changes: 4 additions & 1 deletion train.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import numpy as np
import h5py

os.environ['KERAS_BACKEND'] = 'tensorflow'
import plaidml.keras
plaidml.keras.install_backend()

#os.environ['KERAS_BACKEND'] = 'tensorflow'

from keras.layers.convolutional import Convolution2D, Conv2D
from keras.layers.convolutional import MaxPooling2D
Expand Down