wbenbihi / hourglasstensorflow

Tensorflow implementation of Stacked Hourglass Networks for Human Pose Estimation
MIT License
479 stars 177 forks source link

An error in generating heatmaps from inference.py #39

Closed mengyuest closed 2 years ago

mengyuest commented 6 years ago

I encountered an error in generating heatmaps from inference.py Later on I found out that, in the definition of predictHM(self, img) function at line 125 in inference.py,

self.predict.pred( self, img / 255, debug = False, sess = None)

I think that should be

self.predict.pred( img / 255, debug = False, sess = None)

Or there will be an issue complaining for the conflict of "keyword" and "position argument" for debug. I think this may be just a typo.

Also here is a short script (example) for visualizing keypoints on a cropped image (to any one else who wants to use this package)

from inference import Inference
import cv2
import numpy as np
infer=Inference()
img=cv2.imread("raw_image256.jpg")
hms=infer.predictHM(img)
new_img=np.array(img)
for i in range(np.shape(hms)[3]):
    index=np.argmax(hms[0,:,:,i])
    x=index%64*4
    y=int(index/64)*4
    new_img=cv2.circle(new_img,(x,y),3,(0,0,255),-1)
cv2.imwrite("new_image256.jpg",new_img)

Followed is the result.

new_ron256_5

WilliamYi96 commented 5 years ago

@mengyuest Thanks for your good example. I wonder what version you are using to get the result. v0.1 or v0.3? I'm looking forward to your early reply.

xiaoxin05 commented 4 years ago

I encountered an error in generating heatmaps from inference.py Later on I found out that, in the definition of predictHM(self, img) function at line 125 in inference.py, self.predict.pred( self, img / 255, debug = False, sess = None) I think that should be self.predict.pred( img / 255, debug = False, sess = None) Or there will be an issue complaining for the conflict of "keyword" and "position argument" for debug. I think this may be just a typo. Also here is a short script (example) for visualizing keypoints on a cropped image (to any one else who wants to use this package) from inference import Inference import cv2 import numpy as np infer=Inference() img=cv2.imread("raw_image256.jpg") hms=infer.predictHM(img) new_img=np.array(img) for i in range(np.shape(hms)[3]): index=np.argmax(hms[0,:,:,i]) x=index%644 y=int(index/64)4 new_img=cv2.circle(new_img,(x,y),3,(0,0,255),-1) cv2.imwrite("new_image256.jpg",new_img) Followed is the result.

hi,This is based on the original image, right? The output key should be 64 by 64,I don't understand why? —— y=int(index/64)*4

mengyuest commented 4 years ago

@mengyuest Thanks for your good example. I wonder what version you are using to get the result. v0.1 or v0.3? I'm looking forward to your early reply.

I am not sure about this. I think I used v0.3?

mengyuest commented 4 years ago

I encountered an error in generating heatmaps from inference.py Later on I found out that, in the definition of predictHM(self, img) function at line 125 in inference.py, self.predict.pred( self, img / 255, debug = False, sess = None) I think that should be self.predict.pred( img / 255, debug = False, sess = None) Or there will be an issue complaining for the conflict of "keyword" and "position argument" for debug. I think this may be just a typo. Also here is a short script (example) for visualizing keypoints on a cropped image (to any one else who wants to use this package) from inference import Inference import cv2 import numpy as np infer=Inference() img=cv2.imread("raw_image256.jpg") hms=infer.predictHM(img) new_img=np.array(img) for i in range(np.shape(hms)[3]): index=np.argmax(hms[0,:,:,i]) x=index%644 y=int(index/64)4 new_img=cv2.circle(new_img,(x,y),3,(0,0,255),-1) cv2.imwrite("new_image256.jpg",new_img) Followed is the result.

hi,This is based on the original image, right? The output key should be 64 by 64,I don't understand why? —— y=int(index/64)*4

Yes. Original image is 256x256x3. And I use y=int(index/64)*4 is because np.argmax returns the 1d index. (Python 3.7.3)

>>> import numpy as np
>>> np.argmax([[1,2,3],[6,5,4]])
3
>>> np.argmax([[1,2,3],[4,5,6]])
5

I use y=int(index/64)*4 because I want to first find the corr. row in the 64x64 map, then x4 to project to the original image resolution. You can also use y=index//64*4 in python3