Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import os
|
2 |
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
3 |
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
|
4 |
-
|
5 |
import tensorflow as tf
|
6 |
import tf_bodypix
|
7 |
from tf_bodypix.api import download_model, load_model, BodyPixModelPaths
|
@@ -30,44 +29,33 @@ rainbow = [
|
|
30 |
def process_images(front_img, side_img, real_height_cm):
|
31 |
fimage_array = preprocessing.image.img_to_array(front_img)
|
32 |
simage_array = preprocessing.image.img_to_array(side_img)
|
33 |
-
|
34 |
# bodypix prediction
|
35 |
frontresult = bodypix_model.predict_single(fimage_array)
|
36 |
sideresult = bodypix_model.predict_single(simage_array)
|
37 |
-
|
38 |
front_mask = frontresult.get_mask(threshold=0.75)
|
39 |
side_mask = sideresult.get_mask(threshold=0.75)
|
40 |
-
|
41 |
-
# preprocessing.image.save_img(f'{output_path}/frontbodypix-mask.jpg',front_mask)
|
42 |
-
# preprocessing.image.save_img(f'{output_path}/sidebodypix-mask.jpg',side_mask)
|
43 |
-
|
44 |
front_colored_mask = frontresult.get_colored_part_mask(front_mask, rainbow)
|
45 |
side_colored_mask = sideresult.get_colored_part_mask(side_mask, rainbow)
|
46 |
-
|
47 |
-
# preprocessing.image.save_img(f'{output_path}/frontbodypix-colored-mask.jpg',front_colored_mask)
|
48 |
-
# preprocessing.image.save_img(f'{output_path}/sidebodypix-colored-mask.jpg',side_colored_mask)
|
49 |
-
|
50 |
frontposes = frontresult.get_poses()
|
51 |
front_image_with_poses = draw_poses(
|
52 |
-
fimage_array.copy(),
|
53 |
frontposes,
|
54 |
keypoints_color=(255, 100, 100),
|
55 |
skeleton_color=(100, 100, 255)
|
56 |
)
|
57 |
-
|
58 |
sideposes = sideresult.get_poses()
|
59 |
side_image_with_poses = draw_poses(
|
60 |
-
simage_array.copy(),
|
61 |
sideposes,
|
62 |
keypoints_color=(255, 100, 100),
|
63 |
skeleton_color=(100, 100, 255)
|
64 |
)
|
65 |
-
|
66 |
-
# print(np.array(side_colored_mask).shape)
|
67 |
-
|
68 |
-
# preprocessing.image.save_img(f'{output_path}/frontbodypix-poses.jpg', front_image_with_poses)
|
69 |
-
# preprocessing.image.save_img(f'{output_path}/sidebodypix-poses.jpg', side_image_with_poses)
|
70 |
-
|
71 |
body_sizes = measure_body_sizes(side_colored_mask, front_colored_mask, sideposes, frontposes, real_height_cm, rainbow)
|
72 |
measurements_df = pd.DataFrame([body_sizes[0]])
|
73 |
return measurements_df
|
@@ -76,15 +64,15 @@ def process_images(front_img, side_img, real_height_cm):
|
|
76 |
interface = gr.Interface(
|
77 |
fn=process_images,
|
78 |
inputs=[
|
79 |
-
gr.Image(
|
80 |
-
gr.Image(
|
81 |
gr.Number(label="Enter Your Height (cm)")
|
82 |
],
|
83 |
outputs=[
|
84 |
gr.DataFrame(label="Body Size Measurements")
|
85 |
],
|
86 |
title="Body Sizing System Demo",
|
87 |
-
description="
|
88 |
)
|
89 |
|
90 |
# Launch the app
|
|
|
1 |
import os
|
2 |
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
3 |
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
|
|
|
4 |
import tensorflow as tf
|
5 |
import tf_bodypix
|
6 |
from tf_bodypix.api import download_model, load_model, BodyPixModelPaths
|
|
|
29 |
def process_images(front_img, side_img, real_height_cm):
|
30 |
fimage_array = preprocessing.image.img_to_array(front_img)
|
31 |
simage_array = preprocessing.image.img_to_array(side_img)
|
32 |
+
|
33 |
# bodypix prediction
|
34 |
frontresult = bodypix_model.predict_single(fimage_array)
|
35 |
sideresult = bodypix_model.predict_single(simage_array)
|
36 |
+
|
37 |
front_mask = frontresult.get_mask(threshold=0.75)
|
38 |
side_mask = sideresult.get_mask(threshold=0.75)
|
39 |
+
|
|
|
|
|
|
|
40 |
front_colored_mask = frontresult.get_colored_part_mask(front_mask, rainbow)
|
41 |
side_colored_mask = sideresult.get_colored_part_mask(side_mask, rainbow)
|
42 |
+
|
|
|
|
|
|
|
43 |
frontposes = frontresult.get_poses()
|
44 |
front_image_with_poses = draw_poses(
|
45 |
+
fimage_array.copy(),
|
46 |
frontposes,
|
47 |
keypoints_color=(255, 100, 100),
|
48 |
skeleton_color=(100, 100, 255)
|
49 |
)
|
50 |
+
|
51 |
sideposes = sideresult.get_poses()
|
52 |
side_image_with_poses = draw_poses(
|
53 |
+
simage_array.copy(),
|
54 |
sideposes,
|
55 |
keypoints_color=(255, 100, 100),
|
56 |
skeleton_color=(100, 100, 255)
|
57 |
)
|
58 |
+
|
|
|
|
|
|
|
|
|
|
|
59 |
body_sizes = measure_body_sizes(side_colored_mask, front_colored_mask, sideposes, frontposes, real_height_cm, rainbow)
|
60 |
measurements_df = pd.DataFrame([body_sizes[0]])
|
61 |
return measurements_df
|
|
|
64 |
interface = gr.Interface(
|
65 |
fn=process_images,
|
66 |
inputs=[
|
67 |
+
gr.Image(sources="webcam", type="numpy", label="Front Pose"),
|
68 |
+
gr.Image(sources="webcam", type="numpy", label="Side Pose"),
|
69 |
gr.Number(label="Enter Your Height (cm)")
|
70 |
],
|
71 |
outputs=[
|
72 |
gr.DataFrame(label="Body Size Measurements")
|
73 |
],
|
74 |
title="Body Sizing System Demo",
|
75 |
+
description="Capture two webcam images: Front View and Side View, and input your height in cm."
|
76 |
)
|
77 |
|
78 |
# Launch the app
|