Delete partial_datasets/copy_images.py with huggingface_hub
Browse files
partial_datasets/copy_images.py
DELETED
|
@@ -1,54 +0,0 @@
|
|
| 1 |
-
import json
|
| 2 |
-
import shutil
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
|
| 5 |
-
# Define target directory where JSON files are located
|
| 6 |
-
target_dir = Path("/home/jiaxin/VLM-Gym/current/inference/inference_dataset/partial_datasets/zoomin")
|
| 7 |
-
|
| 8 |
-
# Find all JSON files
|
| 9 |
-
json_files = list(target_dir.rglob("initial_state.json"))
|
| 10 |
-
print(f"Found {len(json_files)} JSON files")
|
| 11 |
-
|
| 12 |
-
# Track copied images to avoid duplicates
|
| 13 |
-
copied_images = set()
|
| 14 |
-
copied_count = 0
|
| 15 |
-
missing_count = 0
|
| 16 |
-
|
| 17 |
-
for json_file in json_files:
|
| 18 |
-
# Read the JSON file
|
| 19 |
-
with open(json_file, 'r') as f:
|
| 20 |
-
data = json.load(f)
|
| 21 |
-
|
| 22 |
-
# Get the image path
|
| 23 |
-
if 'image_name' in data:
|
| 24 |
-
image_path = Path(data['image_name'])
|
| 25 |
-
|
| 26 |
-
# Check if image exists
|
| 27 |
-
if not image_path.exists():
|
| 28 |
-
print(f"Warning: Image not found: {image_path}")
|
| 29 |
-
missing_count += 1
|
| 30 |
-
continue
|
| 31 |
-
|
| 32 |
-
# Get the image filename
|
| 33 |
-
image_filename = image_path.name
|
| 34 |
-
|
| 35 |
-
# Skip if we've already copied this image
|
| 36 |
-
if image_filename in copied_images:
|
| 37 |
-
continue
|
| 38 |
-
|
| 39 |
-
# Copy the image to target directory
|
| 40 |
-
target_image_path = target_dir / image_filename
|
| 41 |
-
try:
|
| 42 |
-
shutil.copy2(image_path, target_image_path)
|
| 43 |
-
copied_images.add(image_filename)
|
| 44 |
-
copied_count += 1
|
| 45 |
-
if copied_count % 10 == 0:
|
| 46 |
-
print(f"Copied {copied_count} images...")
|
| 47 |
-
except Exception as e:
|
| 48 |
-
print(f"Error copying {image_path}: {e}")
|
| 49 |
-
missing_count += 1
|
| 50 |
-
|
| 51 |
-
print(f"\nDone! Copied {copied_count} unique images to {target_dir}")
|
| 52 |
-
if missing_count > 0:
|
| 53 |
-
print(f"Warning: {missing_count} images were missing or had errors")
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|