hourglasstensorflow icon indicating copy to clipboard operation
hourglasstensorflow copied to clipboard

An error in generating heatmaps from inference.py

Open mengyuest opened this issue 6 years ago • 4 comments

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

mengyuest avatar Jun 13 '18 22:06 mengyuest

@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.

WilliamYi96 avatar Jul 20 '19 11:07 WilliamYi96

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.

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

xiaoxin05 avatar Dec 17 '19 07:12 xiaoxin05

@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 avatar Dec 17 '19 15:12 mengyuest

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.

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

mengyuest avatar Dec 17 '19 15:12 mengyuest