| 78 | |
| 79 | |
| 80 | def extract_and_validate_json(input_string): |
| 81 | try: |
| 82 | json_obj = json.loads(input_string) |
| 83 | jsonschema.validate(json_obj, EXTRACT_SCHEMA) |
| 84 | return json_obj |
| 85 | except json.JSONDecodeError as e: |
| 86 | print("Error, JSON is NOT valid.") |
| 87 | return input_string |
| 88 | except Exception as e: |
| 89 | print(f"Error, JSON is NOT valid according to the schema.{input_string}", e) |
| 90 | return input_string |
| 91 | |
| 92 | def load_image(episode, image_path, data_name): |
| 93 | # resize the image proportionally so that the longer side is at most 1120 |