File size: 4,126 Bytes
18a82fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python
"""
Debug script to check dataset output types
Save this as: scripts/debug_dataset.py
"""
import sys
from pathlib import Path

# Add project root to Python path
project_root = Path(__file__).parent.parent
sys.path.append(str(project_root))

import torch
from src.data.data_utils import create_data_loaders

def debug_dataset():
    """Debug dataset to find the data type issue"""
    
    print("πŸ—οΈ Project structure debug")
    print(f"πŸ“ Script location: {Path(__file__).parent}")
    print(f"πŸ“ Project root: {project_root}")
    print(f"πŸ“ Data directory: {project_root / 'data'}")
    
    # Check if data files exist
    data_dir = project_root / 'data'
    train_split = data_dir / 'splits' / 'train.json'
    val_split = data_dir / 'splits' / 'val.json'
    
    print(f"\nπŸ“‹ File existence check:")
    print(f"  Train split: {train_split.exists()} - {train_split}")
    print(f"  Val split: {val_split.exists()} - {val_split}")
    
    if not train_split.exists():
        print("❌ Train split file not found!")
        return
    
    # Create minimal config for debugging
    config = {
        'data_dir': str(data_dir),  # Use absolute path
        'batch_size': 4,  # Small batch for debugging
        'num_workers': 0,  # No multiprocessing for easier debugging
        'use_cached': False,
        'model_name': 'resnet50',
        'num_classes': 5
    }
    
    print(f"\nπŸ” Creating data loaders with config:")
    for key, value in config.items():
        print(f"  {key}: {value}")
    
    try:
        train_loader, val_loader, class_weights, class_names = create_data_loaders(config)
        print(f"βœ… Data loaders created successfully")
        print(f"πŸ“Š Class names: {class_names}")
        print(f"πŸ“Š Train dataset size: {len(train_loader.dataset)}")
        print(f"πŸ“Š Val dataset size: {len(val_loader.dataset)}")
        
        # Check first batch
        print(f"\nπŸ”¬ Checking first batch...")
        for i, batch in enumerate(train_loader):
            print(f"\nBatch {i}:")
            print(f"  Type of batch: {type(batch)}")
            
            if isinstance(batch, (list, tuple)):
                print(f"  Batch length: {len(batch)}")
                for j, item in enumerate(batch):
                    print(f"    Item {j}: type={type(item)}")
                    if hasattr(item, 'shape'):
                        print(f"             shape={item.shape}")
                    if hasattr(item, 'dtype'):
                        print(f"             dtype={item.dtype}")
                    
                    # If it's supposed to be a tensor but isn't, show content
                    if not isinstance(item, torch.Tensor):
                        try:
                            if hasattr(item, '__iter__') and not isinstance(item, str):
                                content = list(item)[:5] if len(item) > 5 else list(item)
                                print(f"             content preview: {content}")
                            else:
                                print(f"             content: {item}")
                        except Exception as e:
                            print(f"             content preview error: {e}")
            else:
                print(f"  Batch content: {batch}")
            
            # Only check first batch
            break
            
    except Exception as e:
        print(f"❌ Error creating data loaders: {e}")
        import traceback
        traceback.print_exc()
        
        # Try to load just the JSON to see the data format
        print(f"\nπŸ” Checking raw JSON data...")
        try:
            import json
            with open(train_split, 'r') as f:
                data = json.load(f)
            print(f"πŸ“„ JSON loaded successfully: {len(data)} items")
            if data:
                print(f"πŸ“‹ First item keys: {list(data[0].keys())}")
                print(f"πŸ“‹ First item: {data[0]}")
        except Exception as json_e:
            print(f"❌ Error reading JSON: {json_e}")

if __name__ == '__main__':
    debug_dataset()