aw1app commited on
Commit
40494ef
·
1 Parent(s): 7cc7ee4

Fix: Adaptive gripper threshold with debug logging

Browse files
Files changed (1) hide show
  1. app.py +37 -1
app.py CHANGED
@@ -129,7 +129,43 @@ def predict(inst, img1, img2):
129
  'qz': float(ac[6])
130
  })
131
 
132
- grip = [int(g > 0.5) for g in gripper_np]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
 
134
  traj_plot = plot_traj(acts)
135
  grip_plot = plot_grip(grip)
 
129
  'qz': float(ac[6])
130
  })
131
 
132
+ # Parse gripper with adaptive normalization
133
+ gripper_np_flat = gripper_np.flatten()
134
+
135
+ # Debug: Print gripper statistics
136
+ print(f" 📊 Gripper stats:")
137
+ print(f" min={gripper_np_flat.min():.4f}, max={gripper_np_flat.max():.4f}")
138
+ print(f" mean={gripper_np_flat.mean():.4f}, std={gripper_np_flat.std():.4f}")
139
+ print(f" sample: {gripper_np_flat[:5]}")
140
+
141
+ # Normalize gripper values if they have variation
142
+ g_range = gripper_np_flat.max() - gripper_np_flat.min()
143
+
144
+ if g_range > 0.1:
145
+ # Significant variation: Normalize to [0, 1] range
146
+ gripper_norm = (gripper_np_flat - gripper_np_flat.min()) / g_range
147
+ grip = [int(g > 0.5) for g in gripper_norm]
148
+ print(f" ✓ Normalized (range={g_range:.4f})")
149
+ elif g_range > 0.01:
150
+ # Small variation: Use adaptive median threshold
151
+ threshold = np.median(gripper_np_flat)
152
+ grip = [int(g > threshold) for g in gripper_np_flat]
153
+ print(f" ✓ Adaptive threshold={threshold:.4f}")
154
+ else:
155
+ # Almost no variation
156
+ mean_val = gripper_np_flat.mean()
157
+ if mean_val > 0.7:
158
+ grip = [int(g > 0.9) for g in gripper_np_flat]
159
+ print(f" ✓ High values (mean={mean_val:.4f}), threshold=0.9")
160
+ elif mean_val < 0.3:
161
+ grip = [int(g > 0.1) for g in gripper_np_flat]
162
+ print(f" ✓ Low values (mean={mean_val:.4f}), threshold=0.1")
163
+ else:
164
+ grip = [0] * len(gripper_np_flat)
165
+ print(f" ⚠ No variation, defaulting to OPEN")
166
+
167
+ print(f" 🤖 Result: {sum(grip)}/{len(grip)} CLOSED")
168
+
169
 
170
  traj_plot = plot_traj(acts)
171
  grip_plot = plot_grip(grip)