SakshiRathi77 commited on
Commit
9d67f5e
·
verified ·
1 Parent(s): af98fd6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -5
app.py CHANGED
@@ -45,16 +45,40 @@ def planogram_compliance_check(planogram_image, master_planogram_image, annotati
45
 
46
  return compliance_score, annotated_image
47
 
48
- # Define the function to run planogram compliance check
49
  def run_compliance_check(planogram_img, master_planogram_img, sorted_xml_df, result_list):
50
- # Perform further processing and calculation of compliance score
51
- compliance_score = 0.0 # Placeholder for actual score calculation
52
- annotated_image = None # Placeholder for annotated image
 
 
 
 
 
 
 
 
 
 
 
53
 
54
- # Your compliance score calculation and image annotation logic here
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
  return compliance_score, annotated_image
57
 
 
58
  # Gradio interface
59
  planogram_check_interface = gr.Interface(
60
  fn=planogram_compliance_check,
 
45
 
46
  return compliance_score, annotated_image
47
 
 
48
  def run_compliance_check(planogram_img, master_planogram_img, sorted_xml_df, result_list):
49
+ # Placeholder for actual score calculation
50
+ compliance_score = 0.0
51
+
52
+ # Placeholder for annotated image
53
+ annotated_image = planogram_img.copy()
54
+
55
+ if sorted_xml_df is not None:
56
+ annotate_df = sorted_xml_df[["xmin", "ymin", "xmax", "ymax", "line_number", "cls"]].astype(int)
57
+ else:
58
+ annotate_df = None
59
+
60
+ mask = master_table != non_null_product
61
+ m_detected_table = np.ma.masked_array(master_table, mask=mask)
62
+ m_annotated_table = np.ma.masked_array(detected_table, mask=mask)
63
 
64
+ # wrong_indexes = np.ravel_multi_index(master_table*mask != detected_table*mask, master_table.shape)
65
+ wrong_indexes = np.where(master_table != detected_table)
66
+ correct_indexes = np.where(master_table == detected_table)
67
+
68
+ # Annotate planogram compliance on the image
69
+ annotated_image = annotate_planogram_compliance(
70
+ annotated_image, annotate_df, correct_indexes, wrong_indexes, target_names
71
+ )
72
+
73
+ # Calculate compliance score
74
+ correct_matches = (np.ma.masked_equal(master_table, non_null_product) == detected_table).sum()
75
+ total_products = (master_table != non_null_product).sum()
76
+ if total_products != 0:
77
+ compliance_score = correct_matches / total_products
78
 
79
  return compliance_score, annotated_image
80
 
81
+
82
  # Gradio interface
83
  planogram_check_interface = gr.Interface(
84
  fn=planogram_compliance_check,