File size: 2,842 Bytes
c4a514c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""
extract_dataset.py — MFAF-Net Dataset Extraction Utility

Extracts Complete_PlasticSurgery_Datasets.zip into the `data/` directory
and prints an extraction summary including procedure subfolders and metadata.

Usage:
    python extract_dataset.py [path_to_zip]
"""

import os
import sys
import zipfile

DEFAULT_ZIP_PATHS = [
    r'C:\Users\ARUL RAJ HARESH\Downloads\Complete_PlasticSurgery_Datasets.zip',
    os.path.join(os.path.dirname(__file__), 'Complete_PlasticSurgery_Datasets.zip'),
    os.path.join(os.path.dirname(__file__), 'data', 'Complete_PlasticSurgery_Datasets.zip'),
]

TARGET_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data')


def find_zip():
    if len(sys.argv) > 1 and os.path.isfile(sys.argv[1]):
        return sys.argv[1]
    for p in DEFAULT_ZIP_PATHS:
        if os.path.isfile(p):
            return p
    return None


def extract():
    print("=" * 60)
    print("MFAF-Net — Complete Plastic Surgery Dataset Extraction")
    print("=" * 60)

    zip_path = find_zip()
    if not zip_path:
        print("[ERROR] Complete_PlasticSurgery_Datasets.zip not found.")
        print("Looked in:")
        for p in DEFAULT_ZIP_PATHS:
            print(f"  - {p}")
        print("\nPlease specify the zip path:")
        print("  python extract_dataset.py <path_to_zip>")
        sys.exit(1)

    print(f"Found archive: {zip_path}")
    print(f"Archive size:  {os.path.getsize(zip_path) / (1024*1024):.2f} MB")
    print(f"Extracting to: {TARGET_DIR}")

    os.makedirs(TARGET_DIR, exist_ok=True)

    with zipfile.ZipFile(zip_path, 'r') as z:
        names = z.namelist()
        total = len(names)
        print(f"Total entries in archive: {total}")

        # Analyze directory breakdown
        folders = {}
        for n in names:
            parts = n.strip('/').split('/')
            top = '/'.join(parts[:2]) if len(parts) > 1 else parts[0]
            folders[top] = folders.get(top, 0) + 1

        print("\nArchive contents overview:")
        for k, v in sorted(folders.items())[:20]:
            print(f"  {v:5d} entries  {k}")
        if len(folders) > 20:
            print(f"  ... and {len(folders) - 20} more subdirectories")

        print("\nExtracting files...")
        z.extractall(TARGET_DIR)
        print("Extracted successfully!")

    print("\nVerifying extraction in:", TARGET_DIR)
    extracted_items = os.listdir(TARGET_DIR)
    print(f"Top-level items in data/ ({len(extracted_items)} items):")
    for item in sorted(extracted_items)[:30]:
        item_path = os.path.join(TARGET_DIR, item)
        kind = "DIR " if os.path.isdir(item_path) else "FILE"
        print(f"  [{kind}] {item}")

    print("\nDataset ready for MFAF-Net pipeline.")
    print("Run `python -m mfaf_net.dataset_analysis` to inspect details.")


if __name__ == '__main__':
    extract()