Chris commited on
Commit
c205b8f
1 Parent(s): 2c8cacd

Improvements after call with Peter.

Browse files
README.md CHANGED
@@ -11,3 +11,11 @@ license: apache-2.0
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
14
+
15
+ ## Usage
16
+
17
+ ```python app.py```
18
+
19
+ ## Notes
20
+
21
+ body_shape_measures_normalised is not being used because the input can't be normalised. Keeping it for future reference.
app.py CHANGED
@@ -5,7 +5,7 @@ os.system("pip install 'mmcv>=2.0.0rc4,<2.1.0'")
5
  os.system("pip install 'mmdet>=3.0.0,<4.0.0'")
6
  os.system("pip install 'mmpose'")
7
 
8
- from keypoints_extraction import predict_pose
9
  from calculate_measures import calculate_all_measures
10
  from calculate_masks import calculate_seg_mask
11
  from select_body_shape import select_body_shape
@@ -14,10 +14,10 @@ import gradio as gr
14
 
15
  def generate_output(front_img_path, side_img_path):
16
  # TODO: These file names will need to be unique in case of multiple requests at once, and they will need to be deleted after the function is done.
17
- front_keypoint_result = predict_pose(front_img_path, "front.jpg")
18
- side_keypoint_result = predict_pose(side_img_path, "side.jpg")
 
19
 
20
- # TODO: LOW PRIORITY: Should we create the image separately? Seems weird to get it as a result from this only to use it in something else below.
21
  front_image = front_keypoint_result[0]
22
  side_image = side_keypoint_result[0]
23
 
@@ -25,28 +25,24 @@ def generate_output(front_img_path, side_img_path):
25
  side_keypoint_data = side_keypoint_result[1]
26
 
27
  front_seg_mask = calculate_seg_mask(front_img_path)
28
- # TODO: Is this the correct mask? In the original code there is a function called 'get_rcnn_mask' which is not used anywhere.
29
- # The name implies that it should be a rcnn mask, but the code actually requests a seg mask.
30
- # If we don't need a rcnn mask, then delete the rcnn code from calculate_masks.py and rename side_rcnn_mask to side_seg_mask.
31
- side_rcnn_mask = calculate_seg_mask(side_img_path)
32
 
33
- measures_data_frame = calculate_all_measures(front_image, side_image, front_keypoint_data, side_keypoint_data, front_seg_mask, side_rcnn_mask)
34
 
35
- # TODO: Normalise the measures somehow? Don't understand how this works yet if it is for a single person. Do we need to do this? Or not?
36
  normalised_measures_data_frame = measures_data_frame
37
 
38
- selected_body_shape = select_body_shape(normalised_measures_data_frame)
 
 
39
 
40
- return (selected_body_shape)
41
 
42
  input_image_front = gr.inputs.Image(type='pil', label="Front Image")
43
  input_image_side = gr.inputs.Image(type='pil', label="Side Image")
44
- # output_image_front = gr.outputs.Image(type="pil", label="Front Output Image")
45
- # output_text_front = gr.outputs.Textbox(label="Front Output Text")
46
- # output_image_side = gr.outputs.Image(type="pil", label="Front Output Image")
47
- # output_text_side = gr.outputs.Textbox(label="Side Output Text")
48
  output_body_shape = gr.outputs.Textbox(label="Body Shape")
 
49
 
50
  title = "ShopByShape"
51
- iface = gr.Interface(fn=generate_output, inputs=[input_image_front, input_image_side], outputs=[output_body_shape], title=title)
52
  iface.launch()
 
5
  os.system("pip install 'mmdet>=3.0.0,<4.0.0'")
6
  os.system("pip install 'mmpose'")
7
 
8
+ from keypoints_extraction import predict_poses
9
  from calculate_measures import calculate_all_measures
10
  from calculate_masks import calculate_seg_mask
11
  from select_body_shape import select_body_shape
 
14
 
15
  def generate_output(front_img_path, side_img_path):
16
  # TODO: These file names will need to be unique in case of multiple requests at once, and they will need to be deleted after the function is done.
17
+ keypoint_results = predict_poses(front_img_path, "front.jpg", side_img_path, "side.jpg")
18
+ front_keypoint_result = keypoint_results[0]
19
+ side_keypoint_result = keypoint_results[1]
20
 
 
21
  front_image = front_keypoint_result[0]
22
  side_image = side_keypoint_result[0]
23
 
 
25
  side_keypoint_data = side_keypoint_result[1]
26
 
27
  front_seg_mask = calculate_seg_mask(front_img_path)
28
+ side_seg_mask = calculate_seg_mask(side_img_path)
 
 
 
29
 
30
+ measures_data_frame = calculate_all_measures(front_image, side_image, front_keypoint_data, side_keypoint_data, front_seg_mask, side_seg_mask)
31
 
32
+ # We can't normalise the measures because we don't have multiple images in this case, so just use the measures directly.
33
  normalised_measures_data_frame = measures_data_frame
34
 
35
+ body_shape_result = select_body_shape(normalised_measures_data_frame)
36
+ selected_body_shape = body_shape_result[0]
37
+ calculation_information = body_shape_result[1]
38
 
39
+ return (selected_body_shape, calculation_information)
40
 
41
  input_image_front = gr.inputs.Image(type='pil', label="Front Image")
42
  input_image_side = gr.inputs.Image(type='pil', label="Side Image")
 
 
 
 
43
  output_body_shape = gr.outputs.Textbox(label="Body Shape")
44
+ output_calculation_information = gr.outputs.Textbox(label="Calculation Information")
45
 
46
  title = "ShopByShape"
47
+ iface = gr.Interface(fn=generate_output, inputs=[input_image_front, input_image_side], outputs=[output_body_shape, output_calculation_information], title=title)
48
  iface.launch()
body_shape_lookup.py CHANGED
@@ -2,18 +2,28 @@
2
 
3
  def body_shape_lookup(index):
4
  if index == 1:
5
- return "Hourglass"
6
  elif index == 2:
7
- return "Triangle"
8
  elif index == 3:
9
- return "Inverted Triangle"
10
  elif index == 4:
11
- return "Rectangle"
12
  elif index == 5:
13
- return "Diamond"
14
  elif index == 6:
15
- return "Oval"
16
  elif index == 7:
17
- return "Round"
 
 
 
 
 
 
 
 
 
 
18
  else:
19
  return "Unknown"
 
2
 
3
  def body_shape_lookup(index):
4
  if index == 1:
5
+ return "Skittle"
6
  elif index == 2:
7
+ return "Goblet"
8
  elif index == 3:
9
+ return "Hourglass"
10
  elif index == 4:
11
+ return "Cornet"
12
  elif index == 5:
13
+ return "Cello"
14
  elif index == 6:
15
+ return "Apple"
16
  elif index == 7:
17
+ return "Column"
18
+ elif index == 8:
19
+ return "Bell"
20
+ elif index == 9:
21
+ return "Vase"
22
+ elif index == 10:
23
+ return "Brick"
24
+ elif index == 11:
25
+ return "Lollipop"
26
+ elif index == 12:
27
+ return "Pear"
28
  else:
29
  return "Unknown"
body_shape_measures.csv ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ id,shoulder_width,hip_width,shoulder_to_hip_distance,hip_to_ankle_distance,torso_to_leg_ratio,waist_width,thigh_area,torso_area,lower_torso_area,upper_torso_area,full_side_body_area,thigh_normalised,torso_normalised,thigh_to_torso_ratio_normalised,thigh_to_torso_ratio,upper_torso_normalised,lower_torso_normalised,upper_to_lower_torso_normalised_ratio,upper_to_lower_torso_ratio,shoulder_to_hip_ratio,shoulder_to_waist_ratio,waist_to_hip_ratio,thigh_to_body_ratio,upper_torso_to_body_ratio,front_img_jpg,front_img_json,side_img_jpg,side_img_json
2
+ 1,862,784,1063.125,1693.125,0.627906976744186,620,257624,390342,199277,191065,892199,103.14065385848444,156.27476131272138,0.6599955936076569,0.6599955936076569,76.49352944396225,79.78123186875914,0.9587910295719024,0.9587910295719024,1.0994897959183674,1.3903225806451613,0.7908163265306123,0.2887517246712897,0.21415065473061504,data/body_shape_full_res/body_shape_full_res_jpg/1. Skittle - front_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/1. Skittle - front.jpg,data/body_shape_full_res/body_shape_full_res_jpg/1. Skittle - side_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/1. Skittle - side.jpg
3
+ 2,922,754,1189.5572967529297,1539.4271240234375,0.7727272556065595,661,121384,277283,139575,137708,551325,64.46416065056842,147.25841838851548,0.4377621419272007,0.43776214192720075,73.13344950626504,74.12496888225044,0.9866236790256133,0.9866236790256134,1.2228116710875332,1.394856278366112,0.876657824933687,0.22016777762662676,0.24977644764884596,data/body_shape_full_res/body_shape_full_res_jpg/2. Goblet - front_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/2. Goblet - front.jpg,data/body_shape_full_res/body_shape_full_res_jpg/2. Goblet - side_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/2. Goblet - side.jpg
4
+ 3,965,919,1206.3802032470703,1419.2706298828125,0.8500001182626317,730,179510,324886,159386,165500,683519,91.29107939251269,165.22307180388768,0.5525322728587874,0.5525322728587874,84.16619486079243,81.05687694309525,1.0383597053693547,1.038359705369355,1.0500544069640914,1.321917808219178,0.794341675734494,0.26262620351445976,0.24212933363959158,data/body_shape_full_res/body_shape_full_res_jpg/3. Hourglass - front_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/3. Hourglass - front.jpg,data/body_shape_full_res/body_shape_full_res_jpg/3. Hourglass - side_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/3. Hourglass - side.jpg
5
+ 4,905,697,1054.010498046875,1505.7291259765625,0.7000000729635094,561,147805,291112,144761,146351,586666,72.95402641247145,143.68791676186456,0.5077255489296215,0.5077255489296216,72.23635681804816,71.45155994381638,1.0109836212792118,1.010983621279212,1.2984218077474892,1.6131907308377897,0.8048780487804879,0.25194062720525817,0.24946221529797194,data/body_shape_full_res/body_shape_full_res_jpg/4. Cornet - front_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/4. Cornet - front.jpg,data/body_shape_full_res/body_shape_full_res_jpg/4. Cornet - side_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/4. Cornet - side.jpg
6
+ 5,926,722,940.0780792236328,1566.796875,0.5999999707834704,602,159618,299091,159016,140075,612306,81.38949821484591,152.5070255896984,0.5336770414355497,0.5336770414355497,71.42448823092973,81.08253735876866,0.8808862001308045,0.8808862001308044,1.2825484764542936,1.5382059800664452,0.8337950138504155,0.2606833837982969,0.2287663357863552,data/body_shape_full_res/body_shape_full_res_jpg/5. Cello - Front_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/5. Cello - Front.jpg,data/body_shape_full_res/body_shape_full_res_jpg/5. Cello - side_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/5. Cello - side.jpg
7
+ 6,890,873,1077.6822814941406,1486.4581298828125,0.7250000923867943,802,137990,314409,165422,148987,595719,77.41391438883764,176.38692230654434,0.4388869275370616,0.4388869275370616,83.58335287375718,92.80356943278716,0.9006480395594298,0.9006480395594298,1.0194730813287514,1.1097256857855362,0.9186712485681557,0.23163605659715403,0.25009610235698376,data/body_shape_full_res/body_shape_full_res_jpg/6. Apple - front_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/6. Apple - front.jpg,data/body_shape_full_res/body_shape_full_res_jpg/6. Apple - side_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/6. Apple - side.jpg
8
+ 7,866,759,1028.59375,1560.625,0.6590909090909091,719,134694,231452,118696,112756,510697,73.00696475699573,125.45182418620112,0.581952197431865,0.5819521974318649,61.11610998366527,64.33571420253585,0.9499561906045696,0.9499561906045697,1.1409749670619236,1.2044506258692629,0.9472990777338604,0.2637454302649125,0.22078845186088816,data/body_shape_full_res/body_shape_full_res_jpg/7. Column - front_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/7. Column - front.jpg,data/body_shape_full_res/body_shape_full_res_jpg/7. Column - side_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/7. Column - side.jpg
9
+ 8,895,859,1074.1015625,1351.2890625,0.7948717948717948,764,134058,225517,122004,103513,493213,79.88289035868203,134.381758530031,0.5944474252495378,0.5944474252495378,61.68164249577237,72.70011603425861,0.8484393954296581,0.8484393954296581,1.0419091967403957,1.1714659685863875,0.889406286379511,0.27180548768990276,0.20987484109299634,data/body_shape_full_res/body_shape_full_res_jpg/8. Bell - front_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/8. Bell - front.jpg,data/body_shape_full_res/body_shape_full_res_jpg/8. Bell - side_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/8. Bell - side.jpg
10
+ 9,909,759,1098.4505310058594,1477.2266845703125,0.7435896890295958,625,121161,246871,117556,129315,505260,67.14540601505387,136.81179198209296,0.49078668616402893,0.490786686164029,71.66421685886293,65.14757512323003,1.1000289223859268,1.1000289223859268,1.1976284584980237,1.4544,0.8234519104084321,0.23979931124569528,0.2559375371096069,data/body_shape_full_res/body_shape_full_res_jpg/9. Vase - front_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/9. Vase - front.jpg,data/body_shape_full_res/body_shape_full_res_jpg/9. Vase - side_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/9. Vase - side.jpg
11
+ 10,946,752,947.5520935058594,1421.3280029296875,0.6666667310801829,699,142076,266731,134791,131940,541046,78.54164138333135,147.4527052269022,0.5326564966201903,0.5326564966201904,72.93831585993932,74.51438936696287,0.9788487361915854,0.9788487361915855,1.2579787234042554,1.3533619456366237,0.9295212765957447,0.2625950473712032,0.2438609656110571,data/body_shape_full_res/body_shape_full_res_jpg/10. Brick - front_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/10. Brick - front.jpg,data/body_shape_full_res/body_shape_full_res_jpg/10. Brick - side_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/10. Brick - side.jpg
12
+ 11,829,655,1032.0313415527344,1582.4478759765625,0.6521739876682167,547,145991,282535,135740,146795,590443,69.70126441106437,134.89219705584642,0.51671828269064,0.5167182826906401,70.08512243372671,64.80707462211971,1.0814424635332254,1.0814424635332254,1.265648854961832,1.5155393053016453,0.8351145038167939,0.24725672080116115,0.2486184102445113,data/body_shape_full_res/body_shape_full_res_jpg/11. Lollipop - front_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/11. Lollipop - front.jpg,data/body_shape_full_res/body_shape_full_res_jpg/11. Lollipop - side_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/11. Lollipop - side.jpg
13
+ 12,833,781,1128.3333435058594,1551.4583740234375,0.7272727147552938,575,264681,399328,196932,202396,903281,106.31059900025417,160.39231708197227,0.6628160309319656,0.6628160309319657,81.29348156934364,79.09883551262861,1.0277456177766946,1.0277456177766946,1.0665813060179257,1.448695652173913,0.736235595390525,0.2930217728480949,0.22406759358383493,data/body_shape_full_res/body_shape_full_res_jpg/12. Pear - front_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/12. Pear - front.jpg,data/body_shape_full_res/body_shape_full_res_jpg/12. Pear - side_keypoints.json,data/body_shape_full_res/body_shape_full_res_jpg/12. Pear - side.jpg
body_shape_measures_normalised.csv DELETED
@@ -1,11 +0,0 @@
1
- id,shoulder_width,hip_width,shoulder_to_hip_distance,hip_to_ankle_distance,torso_to_leg_ratio,waist_width,thigh_area,torso_area,lower_torso_area,upper_torso_area,full_side_body_area,thigh_normalised,torso_normalised,thigh_to_torso_ratio_normalised,thigh_to_torso_ratio,upper_torso_normalised,lower_torso_normalised,upper_to_lower_torso_normalised_ratio,upper_to_lower_torso_ratio,shoulder_to_hip_ratio,shoulder_to_waist_ratio,waist_to_hip_ratio,thigh_to_body_ratio,upper_torso_to_body_ratio,front_img_jpg,front_img_json,side_img_jpg,side_img_json
2
- 2A,309,269,323.125,454.39453125,0.7111111111111111,235,34229,50778,25191,25587,129184,39.727990098179454,58.935635899540046,0.6740911418330774,0.6740911418330773,29.697627235447065,29.23800866409298,1.015719899964273,1.015719899964273,1.1486988847583643,1.3148936170212766,0.8736059479553904,0.26496315333168197,0.1980663240029725,data/volunteers_full_res/2. A front.JPG,data/volunteers_full_res/keypoints/2. A front_keypoints.json,data/volunteers_full_res/2. A side.JPG,data/volunteers_full_res/keypoints/2. A side_keypoints.json
3
- 5A,751,784,799.8046875,1538.0859375,0.52,820,359036,478409,244104,234305,1317742,132.59746694466295,176.68373523415272,0.7504791924901079,0.7504791924901079,86.53240759274627,90.15132764140644,0.9598572739488087,0.9598572739488087,0.9579081632653061,0.9158536585365854,1.0459183673469388,0.27246304663583615,0.17780794723094506,data/volunteers_full_res/5. A front.jpg,data/volunteers_full_res/keypoints/5. A front_keypoints.json,data/volunteers_full_res/5. A side.jpg,data/volunteers_full_res/keypoints/5. A side_keypoints.json
4
- 7A,888,771,895.234375,1694.55078125,0.5283018867924528,549,252555,338580,163668,174912,874524,99.19811098210289,132.9868599565259,0.7459241538188905,0.7459241538188907,68.70162930095061,64.28523065557529,1.0687000513234108,1.0687000513234108,1.1517509727626458,1.6174863387978142,0.7120622568093385,0.2887913882294825,0.20000823305020787,data/volunteers_full_res/7. A front.jpg,data/volunteers_full_res/keypoints/7. A front_keypoints.json,data/volunteers_full_res/7. A side.jpg,data/volunteers_full_res/keypoints/7. A side_keypoints.json
5
- 7B,718,696,974.501953125,1446.03515625,0.6739130434782609,537,252642,372623,181265,191358,979634,96.55081855617931,142.40330452917252,0.6780096773414416,0.6780096773414416,73.13024571240474,69.27305881676777,1.0556809091661379,1.0556809091661379,1.0316091954022988,1.3370577281191807,0.771551724137931,0.2578942748005888,0.1953362174036426,data/volunteers_full_res/7. B front.jpg,data/volunteers_full_res/keypoints/7. B front_keypoints.json,data/volunteers_full_res/7. B side.jpg,data/volunteers_full_res/keypoints/7. B side_keypoints.json
6
- 7C,233,198,280.13671875,340.166015625,0.8235294117647058,160,21697,39647,20911,18736,72801,32.398362709200065,59.201635540934454,0.5472545211491412,0.5472545211491412,27.97694260587051,31.22469293506395,0.89598775763952,0.8959877576395199,1.1767676767676767,1.45625,0.8080808080808081,0.2980316204447741,0.25735910221013447,data/volunteers_full_res/7. C front.JPG,data/volunteers_full_res/keypoints/7. C front_keypoints.json,data/volunteers_full_res/7. C side.JPG,data/volunteers_full_res/keypoints/7. C side_keypoints.json
7
- 9A,211,178,259.423828125,306.591796875,0.8461538461538461,141,13005,29217,12972,16245,63173,20.589812332439678,46.257020139707045,0.4451175685388643,0.44511756853886436,25.719454159206656,20.537565980500386,1.2523126734505088,1.2523126734505088,1.1853932584269662,1.49645390070922,0.7921348314606742,0.2058632643692717,0.25715099805296565,data/volunteers_full_res/9. A front.JPG,data/volunteers_full_res/keypoints/9. A front_keypoints.json,data/volunteers_full_res/9. A side.JPG,data/volunteers_full_res/keypoints/9. A side_keypoints.json
8
- 9B,368,314,440.0,700.0,0.6285714285714286,282,54350,88963,42901,46062,225792,43.11781039270131,70.57754859182864,0.6109281386643886,0.6109281386643886,36.54264180880603,34.03490678302261,1.0736812661709516,1.0736812661709518,1.1719745222929936,1.3049645390070923,0.8980891719745223,0.24070826247165533,0.20400191326530612,data/volunteers_full_res/9. B front.jpg,data/volunteers_full_res/keypoints/9. B front_keypoints.json,data/volunteers_full_res/9. B side.jpg,data/volunteers_full_res/keypoints/9. B side_keypoints.json
9
- 10A,189,179,224.580078125,348.486328125,0.6444444444444445,155,13346,21964,10953,11011,49817,23.882954108559645,39.3050505050505,0.6076306683664178,0.6076306683664178,19.704421376393693,19.60062912865681,1.0052953528713595,1.0052953528713595,1.0558659217877095,1.2193548387096773,0.8659217877094972,0.2679005158881506,0.22102896601561717,data/volunteers_full_res/10. A front.JPG,data/volunteers_full_res/keypoints/10. A front_keypoints.json,data/volunteers_full_res/10. A side.JPG,data/volunteers_full_res/keypoints/10. A side_keypoints.json
10
- 11A,203,169,223.330078125,304.541015625,0.7333333333333333,147,16750,30912,15171,15741,63617,25.30289865121034,46.69631063320681,0.5418607660455487,0.5418607660455487,23.77868224887773,22.917628384329078,1.0375716828158987,1.0375716828158987,1.2011834319526626,1.380952380952381,0.8698224852071006,0.26329440243959945,0.24743386201801404,data/volunteers_full_res/11. A front.jpg,data/volunteers_full_res/keypoints/11. A front_keypoints.json,data/volunteers_full_res/11. A side.jpg,data/volunteers_full_res/keypoints/11. A side_keypoints.json
11
- 12A,669,672,783.056640625,1269.091796875,0.6170212765957447,567,211624,335094,170606,164488,813075,90.92243084724528,143.97025404645413,0.6315362256560846,0.6315362256560846,70.67085399199374,73.2994000544604,0.9641395964971924,0.9641395964971924,0.9955357142857143,1.17989417989418,0.84375,0.26027611228976416,0.20230360052885651,data/volunteers_full_res/12. A front.jpg,data/volunteers_full_res/keypoints/12. A front_keypoints.json,data/volunteers_full_res/12. A side.jpg,data/volunteers_full_res/keypoints/12. A side_keypoints.json
 
 
 
 
 
 
 
 
 
 
 
 
body_shape_measures_normalised_updated.csv DELETED
@@ -1,11 +0,0 @@
1
- id,shoulder_width,hip_width,shoulder_to_hip_distance,hip_to_ankle_distance,torso_to_leg_ratio,waist_width,thigh_area,torso_area,lower_torso_area,upper_torso_area,full_side_body_area,thigh_normalised,torso_normalised,thigh_to_torso_ratio_normalised,thigh_to_torso_ratio,upper_torso_normalised,lower_torso_normalised,upper_to_lower_torso_normalised_ratio,upper_to_lower_torso_ratio,shoulder_to_hip_ratio,shoulder_to_waist_ratio,waist_to_hip_ratio,thigh_to_body_ratio,upper_torso_to_body_ratio,front_img_jpg,front_img_json,side_img_jpg,side_img_json
2
- 2A,309,269,-0.6451853254425501,-0.6682325556525112,0.3512052843480335,235,34229,50778,25191,25587,129184,-0.5136746421535362,-0.6393085847116429,0.5341966631577374,0.5341966631577363,-0.6530399046830264,-0.6235671698990638,-0.18048946872604607,-0.18048946872604604,0.46262354383444276,-0.038443926936658726,0.2848605088833572,0.11603850407389217,-0.6352860522185653,data/volunteers_full_res/2. A front.JPG,data/volunteers_full_res/keypoints/2. A front_keypoints.json,data/volunteers_full_res/2. A side.JPG,data/volunteers_full_res/keypoints/2. A side_keypoints.json
3
- 5A,751,784,0.9144271139787139,1.2087976272001555,-1.393368840086257,820,359036,478409,244104,234305,1317742,1.7908025462101405,1.6581076973120041,1.3373436638658922,1.3373436638658922,1.5898707794468867,1.7184597534399404,-0.7675499961012099,-0.7675499961012098,-1.6885839094884345,-2.105222050862348,2.2088413671422513,0.4115935545489668,-1.3509388020203796,data/volunteers_full_res/5. A front.jpg,data/volunteers_full_res/keypoints/5. A front_keypoints.json,data/volunteers_full_res/5. A side.jpg,data/volunteers_full_res/keypoints/5. A side_keypoints.json
4
- 7A,888,771,1.2266563354411533,1.4798058058940855,-1.3175843564008711,549,252555,338580,163668,174912,874524,0.9620258960628703,0.8055256743012406,1.2894518062332987,1.2894518062332998,0.8862023059241599,0.7239466229852285,0.3762791226520531,0.37627912265205304,0.49703650905427676,1.5287976601007285,-1.5188804555519377,1.0550592184153258,-0.5666856621104159,data/volunteers_full_res/7. A front.jpg,data/volunteers_full_res/keypoints/7. A front_keypoints.json,data/volunteers_full_res/7. A side.jpg,data/volunteers_full_res/keypoints/7. A side_keypoints.json
5
- 7B,718,696,1.4860059660807992,1.0493591618169957,0.01163954223114654,537,252642,372623,181265,191358,979634,0.8963355830168163,0.9892525726734528,0.5753963012377995,0.5753963012377995,1.0609718924822236,0.9157212305526141,0.2394609133057007,0.23946091330570068,-0.8575885214005697,0.07635234591621287,-0.8546416455323987,-0.16253115903080398,-0.7317305165035971,data/volunteers_full_res/7. B front.jpg,data/volunteers_full_res/keypoints/7. B front_keypoints.json,data/volunteers_full_res/7. B side.jpg,data/volunteers_full_res/keypoints/7. B side_keypoints.json
6
- 7C,233,198,-0.7858354516068623,-0.8660844259672597,1.3774253575446744,160,21697,39647,20911,18736,72801,-0.6955531203216642,-0.6341185908976849,-0.7993686079294058,-0.7993686079294058,-0.7209444855652456,-0.5471821012653706,-1.4387549608901573,-1.4387549608901582,0.7791053627807573,0.6936939800717078,-0.4467705325621465,1.4191973718580178,1.4593062364358502,data/volunteers_full_res/7. C front.JPG,data/volunteers_full_res/keypoints/7. C front_keypoints.json,data/volunteers_full_res/7. C side.JPG,data/volunteers_full_res/keypoints/7. C side_keypoints.json
7
- 9A,211,178,-0.8536044015374634,-0.9242373480961905,1.5839544420431042,141,13005,29217,12972,16245,63173,-0.9885722682153351,-0.8866846225820019,-1.8732405871833364,-1.8732405871833364,-0.810033330890077,-0.9580863087680326,2.305864794991042,2.3058647949910416,0.8763606978908735,0.9019251126074833,-0.6248177905120642,-2.212964050626634,1.4519546942072203,data/volunteers_full_res/9. A front.JPG,data/volunteers_full_res/keypoints/9. A front_keypoints.json,data/volunteers_full_res/9. A side.JPG,data/volunteers_full_res/keypoints/9. A side_keypoints.json
8
- 9B,368,314,-0.2627907979699269,-0.24282650808339729,-0.40226526773322185,282,54350,88963,42901,46062,225792,-0.4295591307213896,-0.4121599519583041,-0.12990166261860167,-0.12990166261860167,-0.3829103075755036,-0.4391335397560143,0.42862672647856803,0.4286267264785703,0.7250614892098834,-0.08987035878672849,0.558231717572826,-0.8397958260534285,-0.4256038637053921,data/volunteers_full_res/9. B front.jpg,data/volunteers_full_res/keypoints/9. B front_keypoints.json,data/volunteers_full_res/9. B side.jpg,data/volunteers_full_res/keypoints/9. B side_keypoints.json
9
- 10A,189,179,-0.967607048096815,-0.8516730560853955,-0.2573670846406723,155,13346,21964,10953,11011,49817,-0.9068557521025037,-1.0223264573211466,-0.16457139639188673,-0.16457139639188673,-1.0474087761570212,-0.9941101434453615,-0.29004106968943183,-0.2900410696894318,-0.5840885829069261,-0.5332752158903319,0.19906183414420206,0.2317937959738227,0.1758982832290134,data/volunteers_full_res/10. A front.JPG,data/volunteers_full_res/keypoints/10. A front_keypoints.json,data/volunteers_full_res/10. A side.JPG,data/volunteers_full_res/keypoints/10. A side_keypoints.json
10
- 11A,203,169,-0.9716968291393029,-0.9277894463065092,0.5540627406776014,147,16750,30912,15171,15741,63617,-0.871621034320157,-0.8781135022156633,-0.8560787634674033,-0.8560787634674033,-0.886623370048677,-0.866576433381505,0.04915099181033875,0.049150991810338746,1.0543983860547377,0.3036992727189106,0.24261567283875252,0.050276534651395643,1.1086845891110646,data/volunteers_full_res/11. A front.jpg,data/volunteers_full_res/keypoints/11. A front_keypoints.json,data/volunteers_full_res/11. A side.jpg,data/volunteers_full_res/keypoints/11. A side_keypoints.json
11
- 12A,669,672,0.8596304382922542,0.7428807452800266,-0.5077018179835446,567,211624,335094,170606,164488,813075,0.7566719225447575,1.0198257653997465,0.08677258309590243,0.08677258309590243,0.9639151970662792,1.070528089537564,-0.7225470538308504,-0.7225470538308503,-1.2643249750290122,-0.7376568189389741,-0.04850067642283835,-0.06866794381056764,-0.48559890642479764,data/volunteers_full_res/12. A front.jpg,data/volunteers_full_res/keypoints/12. A front_keypoints.json,data/volunteers_full_res/12. A side.jpg,data/volunteers_full_res/keypoints/12. A side_keypoints.json
 
 
 
 
 
 
 
 
 
 
 
 
keypoints_extraction.py CHANGED
@@ -6,21 +6,27 @@ from mmpose.apis import inference_topdown, init_model
6
  from mmpose.utils import register_all_modules
7
  register_all_modules()
8
 
 
 
 
 
9
  def save_image(img, img_path):
10
  # Convert PIL image to OpenCV image
11
  img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
12
  # Save OpenCV image
13
  cv2.imwrite(img_path, img)
14
 
15
- def predict_pose(img, img_path):
16
- save_image(img, img_path)
 
17
 
18
- result = mmpose_coco(img_path)
19
- keypoints = result[0].pred_instances['keypoints'][0]
 
20
 
21
- # Create a dictionary to store keypoints and their names
22
- keypoints_data = {
23
- 'keypoints': keypoints.tolist(),
24
  'keypoint_names': [
25
  'nose',
26
  'left_eye',
@@ -41,14 +47,37 @@ def predict_pose(img, img_path):
41
  'right_ankle'
42
  ]
43
  }
44
- return (img, keypoints_data)
45
-
46
- def mmpose_coco(img_path,
47
- config_file = 'mmpose/td-hm_hrnet-w48_8xb32-210e_coco-256x192.py',
48
- checkpoint_file = 'mmpose/td-hm_hrnet-w48_8xb32-210e_coco-256x192-0e67c616_20220913.pth'):
49
- device = torch.cuda.current_device() if torch.cuda.is_available() else 'cpu'
50
- # coco keypoints:
51
- # https://github.com/open-mmlab/mmpose/blob/master/mmpose/datasets/datasets/top_down/topdown_coco_dataset.py#L28
52
- model = init_model(config_file, checkpoint_file, device=device)
53
- results = inference_topdown(model, img_path)
54
- return results
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  from mmpose.utils import register_all_modules
7
  register_all_modules()
8
 
9
+ # coco keypoints:
10
+ # https://github.com/open-mmlab/mmpose/blob/master/mmpose/datasets/datasets/top_down/topdown_coco_dataset.py#L28
11
+ model = init_model('mmpose/td-hm_hrnet-w48_8xb32-210e_coco-256x192.py', 'mmpose/td-hm_hrnet-w48_8xb32-210e_coco-256x192-0e67c616_20220913.pth', device=torch.cuda.current_device() if torch.cuda.is_available() else 'cpu')
12
+
13
  def save_image(img, img_path):
14
  # Convert PIL image to OpenCV image
15
  img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
16
  # Save OpenCV image
17
  cv2.imwrite(img_path, img)
18
 
19
+ def predict_poses(front_img, front_img_path, side_img, side_img_path):
20
+ save_image(front_img, front_img_path)
21
+ save_image(side_img, side_img_path)
22
 
23
+ mmpose_result = mmpose_coco(front_img_path, side_img_path)
24
+ front_result = mmpose_result[0]
25
+ side_result = mmpose_result[1]
26
 
27
+ front_keypoints = front_result[0].pred_instances['keypoints'][0]
28
+ front_keypoints_data = {
29
+ 'keypoints': front_keypoints.tolist(),
30
  'keypoint_names': [
31
  'nose',
32
  'left_eye',
 
47
  'right_ankle'
48
  ]
49
  }
50
+
51
+ side_keypoints = side_result[0].pred_instances['keypoints'][0]
52
+ side_keypoints_data = {
53
+ 'keypoints': side_keypoints.tolist(),
54
+ 'keypoint_names': [
55
+ 'nose',
56
+ 'left_eye',
57
+ 'right_eye',
58
+ 'left_ear',
59
+ 'right_ear',
60
+ 'left_shoulder',
61
+ 'right_shoulder',
62
+ 'left_elbow',
63
+ 'right_elbow',
64
+ 'left_wrist',
65
+ 'right_wrist',
66
+ 'left_hip',
67
+ 'right_hip',
68
+ 'left_knee',
69
+ 'right_knee',
70
+ 'left_ankle',
71
+ 'right_ankle'
72
+ ]
73
+ }
74
+
75
+ return ((front_img, front_keypoints_data), (side_img, side_keypoints_data))
76
+
77
+ def mmpose_coco(front_img_path,
78
+ side_img_path):
79
+
80
+ front_results = inference_topdown(model, front_img_path)
81
+ side_results = inference_topdown(model, side_img_path)
82
+
83
+ return (front_results, side_results)
select_body_shape.py CHANGED
@@ -4,7 +4,7 @@ from numpy import dot
4
  from numpy.linalg import norm
5
  from body_shape_lookup import body_shape_lookup
6
 
7
- BODY_SHAPE_MEASURES = "body_shape_measures_normalised_updated.csv"
8
 
9
  # selecting specific features
10
  RATIOS_TO_USE = ['shoulder_to_hip_distance',
@@ -39,6 +39,8 @@ def select_body_shape(normalised_body_shape_measures):
39
  # select only the columns corresponding to the ratios
40
  body_shape_ratios = body_shape_df[RATIOS_TO_USE]
41
 
 
 
42
  # calculate euclidean distance for each volunteer
43
  for index, volunteer_row in volunteers_df.iterrows():
44
  print(f"\nProcessing volunteer {volunteer_row['id']}")
@@ -59,13 +61,15 @@ def select_body_shape(normalised_body_shape_measures):
59
  top_scores = top_scores[:3]
60
  break
61
 
62
- print(f"Volunteer {volunteer_row['id']} (body shape {body_index + 1}) Similarity:\t{similarity:.3f}")
 
63
 
64
  # Print the top 3 best body shapes and scores for the current volunteer
65
- print(f"Volunteer {volunteer_row['id']} top 3 body shapes and scores are:")
66
  for i, (score, body_shape) in enumerate(top_scores):
67
  print(f"Rank {i + 1}: Body Shape {body_shape} with score {score:.3f}")
 
68
 
69
  body_shape_index = top_scores[0][1]
70
 
71
- return body_shape_lookup(body_shape_index)
 
4
  from numpy.linalg import norm
5
  from body_shape_lookup import body_shape_lookup
6
 
7
+ BODY_SHAPE_MEASURES = "body_shape_measures.csv"
8
 
9
  # selecting specific features
10
  RATIOS_TO_USE = ['shoulder_to_hip_distance',
 
39
  # select only the columns corresponding to the ratios
40
  body_shape_ratios = body_shape_df[RATIOS_TO_USE]
41
 
42
+ calculation_information = ""
43
+
44
  # calculate euclidean distance for each volunteer
45
  for index, volunteer_row in volunteers_df.iterrows():
46
  print(f"\nProcessing volunteer {volunteer_row['id']}")
 
61
  top_scores = top_scores[:3]
62
  break
63
 
64
+ print(f"(body shape {body_index + 1}) Similarity:\t{similarity:.3f}")
65
+ calculation_information += f"(body shape {body_index + 1}) Similarity:\t{similarity:.3f}\n"
66
 
67
  # Print the top 3 best body shapes and scores for the current volunteer
68
+ print(f"Body shapes and scores are:")
69
  for i, (score, body_shape) in enumerate(top_scores):
70
  print(f"Rank {i + 1}: Body Shape {body_shape} with score {score:.3f}")
71
+ calculation_information += f"Rank {i + 1}: Body Shape {body_shape} with score {score:.3f}\n"
72
 
73
  body_shape_index = top_scores[0][1]
74
 
75
+ return (body_shape_lookup(body_shape_index), calculation_information)
volunteers_measures_normalised_updated.csv DELETED
@@ -1,11 +0,0 @@
1
- id,shoulder_width,hip_width,shoulder_to_hip_distance,hip_to_ankle_distance,torso_to_leg_ratio,waist_width,thigh_area,torso_area,lower_torso_area,upper_torso_area,full_side_body_area,thigh_normalised,torso_normalised,thigh_to_torso_ratio_normalised,thigh_to_torso_ratio,upper_torso_normalised,lower_torso_normalised,upper_to_lower_torso_normalised_ratio,upper_to_lower_torso_ratio,shoulder_to_hip_ratio,shoulder_to_waist_ratio,waist_to_hip_ratio,thigh_to_body_ratio,upper_torso_to_body_ratio,front_img_jpg,front_img_json,side_img_jpg,side_img_json
2
- 2A,309,269,-0.6451853254425501,-0.6682325556525112,0.3512052843480335,235,34229,50778,25191,25587,129184,-0.5136746421535362,-0.6393085847116429,0.5341966631577374,0.5341966631577363,-0.6530399046830264,-0.6235671698990638,-0.18048946872604607,-0.18048946872604604,0.46262354383444276,-0.038443926936658726,0.2848605088833572,0.11603850407389217,-0.6352860522185653,data/volunteers_full_res/2. A front.JPG,data/volunteers_full_res/keypoints/2. A front_keypoints.json,data/volunteers_full_res/2. A side.JPG,data/volunteers_full_res/keypoints/2. A side_keypoints.json
3
- 5A,751,784,0.9144271139787139,1.2087976272001555,-1.393368840086257,820,359036,478409,244104,234305,1317742,1.7908025462101405,1.6581076973120041,1.3373436638658922,1.3373436638658922,1.5898707794468867,1.7184597534399404,-0.7675499961012099,-0.7675499961012098,-1.6885839094884345,-2.105222050862348,2.2088413671422513,0.4115935545489668,-1.3509388020203796,data/volunteers_full_res/5. A front.jpg,data/volunteers_full_res/keypoints/5. A front_keypoints.json,data/volunteers_full_res/5. A side.jpg,data/volunteers_full_res/keypoints/5. A side_keypoints.json
4
- 7A,888,771,1.2266563354411533,1.4798058058940855,-1.3175843564008711,549,252555,338580,163668,174912,874524,0.9620258960628703,0.8055256743012406,1.2894518062332987,1.2894518062332998,0.8862023059241599,0.7239466229852285,0.3762791226520531,0.37627912265205304,0.49703650905427676,1.5287976601007285,-1.5188804555519377,1.0550592184153258,-0.5666856621104159,data/volunteers_full_res/7. A front.jpg,data/volunteers_full_res/keypoints/7. A front_keypoints.json,data/volunteers_full_res/7. A side.jpg,data/volunteers_full_res/keypoints/7. A side_keypoints.json
5
- 7B,718,696,1.4860059660807992,1.0493591618169957,0.01163954223114654,537,252642,372623,181265,191358,979634,0.8963355830168163,0.9892525726734528,0.5753963012377995,0.5753963012377995,1.0609718924822236,0.9157212305526141,0.2394609133057007,0.23946091330570068,-0.8575885214005697,0.07635234591621287,-0.8546416455323987,-0.16253115903080398,-0.7317305165035971,data/volunteers_full_res/7. B front.jpg,data/volunteers_full_res/keypoints/7. B front_keypoints.json,data/volunteers_full_res/7. B side.jpg,data/volunteers_full_res/keypoints/7. B side_keypoints.json
6
- 7C,233,198,-0.7858354516068623,-0.8660844259672597,1.3774253575446744,160,21697,39647,20911,18736,72801,-0.6955531203216642,-0.6341185908976849,-0.7993686079294058,-0.7993686079294058,-0.7209444855652456,-0.5471821012653706,-1.4387549608901573,-1.4387549608901582,0.7791053627807573,0.6936939800717078,-0.4467705325621465,1.4191973718580178,1.4593062364358502,data/volunteers_full_res/7. C front.JPG,data/volunteers_full_res/keypoints/7. C front_keypoints.json,data/volunteers_full_res/7. C side.JPG,data/volunteers_full_res/keypoints/7. C side_keypoints.json
7
- 9A,211,178,-0.8536044015374634,-0.9242373480961905,1.5839544420431042,141,13005,29217,12972,16245,63173,-0.9885722682153351,-0.8866846225820019,-1.8732405871833364,-1.8732405871833364,-0.810033330890077,-0.9580863087680326,2.305864794991042,2.3058647949910416,0.8763606978908735,0.9019251126074833,-0.6248177905120642,-2.212964050626634,1.4519546942072203,data/volunteers_full_res/9. A front.JPG,data/volunteers_full_res/keypoints/9. A front_keypoints.json,data/volunteers_full_res/9. A side.JPG,data/volunteers_full_res/keypoints/9. A side_keypoints.json
8
- 9B,368,314,-0.2627907979699269,-0.24282650808339729,-0.40226526773322185,282,54350,88963,42901,46062,225792,-0.4295591307213896,-0.4121599519583041,-0.12990166261860167,-0.12990166261860167,-0.3829103075755036,-0.4391335397560143,0.42862672647856803,0.4286267264785703,0.7250614892098834,-0.08987035878672849,0.558231717572826,-0.8397958260534285,-0.4256038637053921,data/volunteers_full_res/9. B front.jpg,data/volunteers_full_res/keypoints/9. B front_keypoints.json,data/volunteers_full_res/9. B side.jpg,data/volunteers_full_res/keypoints/9. B side_keypoints.json
9
- 10A,189,179,-0.967607048096815,-0.8516730560853955,-0.2573670846406723,155,13346,21964,10953,11011,49817,-0.9068557521025037,-1.0223264573211466,-0.16457139639188673,-0.16457139639188673,-1.0474087761570212,-0.9941101434453615,-0.29004106968943183,-0.2900410696894318,-0.5840885829069261,-0.5332752158903319,0.19906183414420206,0.2317937959738227,0.1758982832290134,data/volunteers_full_res/10. A front.JPG,data/volunteers_full_res/keypoints/10. A front_keypoints.json,data/volunteers_full_res/10. A side.JPG,data/volunteers_full_res/keypoints/10. A side_keypoints.json
10
- 11A,203,169,-0.9716968291393029,-0.9277894463065092,0.5540627406776014,147,16750,30912,15171,15741,63617,-0.871621034320157,-0.8781135022156633,-0.8560787634674033,-0.8560787634674033,-0.886623370048677,-0.866576433381505,0.04915099181033875,0.049150991810338746,1.0543983860547377,0.3036992727189106,0.24261567283875252,0.050276534651395643,1.1086845891110646,data/volunteers_full_res/11. A front.jpg,data/volunteers_full_res/keypoints/11. A front_keypoints.json,data/volunteers_full_res/11. A side.jpg,data/volunteers_full_res/keypoints/11. A side_keypoints.json
11
- 12A,669,672,0.8596304382922542,0.7428807452800266,-0.5077018179835446,567,211624,335094,170606,164488,813075,0.7566719225447575,1.0198257653997465,0.08677258309590243,0.08677258309590243,0.9639151970662792,1.070528089537564,-0.7225470538308504,-0.7225470538308503,-1.2643249750290122,-0.7376568189389741,-0.04850067642283835,-0.06866794381056764,-0.48559890642479764,data/volunteers_full_res/12. A front.jpg,data/volunteers_full_res/keypoints/12. A front_keypoints.json,data/volunteers_full_res/12. A side.jpg,data/volunteers_full_res/keypoints/12. A side_keypoints.json