(jsonl_file_path, train_episodes, output_test_dir)
| 244 | return set() |
| 245 | |
| 246 | def read_episodes_from_jsonl(jsonl_file_path, train_episodes, output_test_dir): |
| 247 | episodes = {'in_train': [], 'not_in_train': []} |
| 248 | |
| 249 | os.makedirs(output_test_dir, exist_ok=True) |
| 250 | |
| 251 | total_lines = sum(1 for _ in open(jsonl_file_path, 'r', encoding='utf-8')) |
| 252 | |
| 253 | with open(jsonl_file_path, 'r', encoding='utf-8') as file: |
| 254 | for line in tqdm(file, total=total_lines, desc="saving data"): |
| 255 | data = json.loads(line.strip()) |
| 256 | episode_id = data['episode_id'][0] |
| 257 | |
| 258 | episode_data = [] |
| 259 | goal = data['goal'][0] |
| 260 | actions = data['actions'] |
| 261 | screenshot_widths = data['screenshot_widths'] |
| 262 | screenshot_heights = data['screenshot_heights'] |
| 263 | screenshot_path = data['screenshot_path'] |
| 264 | |
| 265 | for index, action in enumerate(actions): |
| 266 | action_data = { |
| 267 | 'action': action, |
| 268 | 'screenshot_width': screenshot_widths[index], |
| 269 | 'screenshot_height': screenshot_heights[index], |
| 270 | 'screenshot_path': screenshot_path[index], |
| 271 | 'low_instruction': data['step_instructions'][index], |
| 272 | 'goal': goal, |
| 273 | 'episode_id': episode_id, |
| 274 | 'step': index, |
| 275 | 'episode_length': len(screenshot_path), |
| 276 | 'ui_trees': data['accessibility_tree'][index] |
| 277 | } |
| 278 | test_data = transform_action_data_and_build_test_data(action_data) |
| 279 | if test_data is not None: |
| 280 | episode_data.append(test_data) |
| 281 | |
| 282 | # add last finish |
| 283 | action_data={ |
| 284 | 'action': "{\"action_type\":\"finish\"}", |
| 285 | 'screenshot_width': screenshot_widths[-1], |
| 286 | 'screenshot_height': screenshot_heights[-1], |
| 287 | 'screenshot_path': screenshot_path[-1], |
| 288 | 'goal': goal, |
| 289 | 'episode_id': episode_id, |
| 290 | 'step': len(actions), |
| 291 | 'episode_length': len(screenshot_path), |
| 292 | 'ui_trees': data['accessibility_tree'][-1], |
| 293 | 'low_instruction': "finish the task" |
| 294 | } |
| 295 | finish_data =transform_action_data_and_build_test_data(action_data) |
| 296 | episode_data.append(finish_data) |
| 297 | |
| 298 | if episode_id in train_episodes: |
| 299 | episodes['in_train'].append(episode_id) |
| 300 | continue |
| 301 | else: |
| 302 | episodes['not_in_train'].append(episode_id) |
| 303 |
no test coverage detected