Я пробую Pos enet - python от Ross Whigtman, доступный в этом GitHub:
https://github.com/rwightman/posenet-python
Я использую следующий код чтобы проверить это на одном изображении:
model = 101
scale_factor = 1.0
notxt = 'store_true'
image_dir = './images'
output_dir = './output'
def main():
with tf.compat.v1.Session() as sess:
model_cfg, model_outputs = posenet.load_model(model, sess)
output_stride = model_cfg['output_stride']
if args.output_dir:
if not os.path.exists(output_dir):
os.makedirs(output_dir)
filenames = [
f.path for f in os.scandir(image_dir) if f.is_file() and f.path.endswith(('.png', '.jpg'))]
start = time.time()
for f in filenames:
input_image, draw_image, output_scale = posenet.read_imgfile(
f, scale_factor=scale_factor, output_stride=output_stride)
heatmaps_result, offsets_result, displacement_fwd_result, displacement_bwd_result = sess.run(
model_outputs,
feed_dict={'image:0': input_image}
)
pose_scores, keypoint_scores, keypoint_coords = posenet.decode_multiple_poses(
heatmaps_result.squeeze(axis=0),
offsets_result.squeeze(axis=0),
displacement_fwd_result.squeeze(axis=0),
displacement_bwd_result.squeeze(axis=0),
output_stride=output_stride,
max_pose_detections=10,
min_pose_score=0.25)
keypoint_coords *= output_scale
if args.output_dir:
draw_image = posenet.draw_skel_and_kp(
draw_image, pose_scores, keypoint_scores, keypoint_coords,
min_pose_score=0.25, min_part_score=0.25)
cv2.imwrite(os.path.join(output_dir, os.path.relpath(f, image_dir)), draw_image)
if not notxt:
print()
print("Results for image: %s" % f)
for pi in range(len(pose_scores)):
if pose_scores[pi] == 0.:
break
print('Pose #%d, score = %f' % (pi, pose_scores[pi]))
for ki, (s, c) in enumerate(zip(keypoint_scores[pi, :], keypoint_coords[pi, :, :])):
print('Keypoint %s, score = %f, coord = %s' % (posenet.PART_NAMES[ki], s, c))
print('Average FPS:', len(filenames) / (time.time() - start))
if __name__ == "__main__":
main()
Однако это вызывает следующую ошибку:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-13-05f825a86194> in <module>
54
55 if __name__ == "__main__":
---> 56 main()
<ipython-input-13-05f825a86194> in main()
2
3 with tf.compat.v1.Session() as sess:
----> 4 model_cfg, model_outputs = posenet.load_model(model, sess)
5 output_stride = model_cfg['output_stride']
6
~/opt/anaconda3/lib/python3.7/site-packages/posenet/model.py in load_model(model_id, sess, model_dir)
40 print('Cannot find model file %s, converting from tfjs...' % model_path)
41 from posenet.converter.tfjs2python import convert
---> 42 convert(model_ord, model_dir, check=False)
43 assert os.path.exists(model_path)
44
~/opt/anaconda3/lib/python3.7/site-packages/posenet/converter/tfjs2python.py in convert(model_id, model_dir, check)
163 variables = load_variables(chkpoint)
164
--> 165 init = tf.global_variables_initializer()
166 with tf.Session() as sess:
167 sess.run(init)
AttributeError: module 'tensorflow' has no attribute 'global_variables_initializer'
Может ли кто-нибудь предоставить информацию о том, что вызывает эту ошибку и как ее исправить ? Спасибо.