File size: 3,703 Bytes
da341b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash

# Usage function
usage() {
    echo "Usage: $0 -s SOURCE_DIR -t TARGET_DIR [-c CHUNK_TYPE] [-h]"
    echo "Uncompress chunked DeepFurniture dataset"
    echo ""
    echo "Required arguments:"
    echo "  -s SOURCE_DIR   Source directory containing the chunked dataset"
    echo "  -t TARGET_DIR   Target directory for the uncompressed dataset"
    echo ""
    echo "Optional arguments:"
    echo "  -c CHUNK_TYPE   Specific chunk type to process (scenes, furnitures, queries)"
    echo "                  If not specified, all chunk types will be processed"
    echo "  -h             Show this help message"
    exit 1
}

# Process command line arguments
while getopts "s:t:c:h" opt; do
    case $opt in
        s) SOURCE_DIR="$OPTARG";;
        t) TARGET_DIR="$OPTARG";;
        c) CHUNK_TYPE="$OPTARG";;
        h) usage;;
        ?) usage;;
    esac
done

# Check required arguments
if [ -z "$SOURCE_DIR" ] || [ -z "$TARGET_DIR" ]; then
    echo "Error: Source and target directories are required"
    usage
fi

# Validate source directory
if [ ! -d "$SOURCE_DIR" ]; then
    echo "Error: Source directory does not exist: $SOURCE_DIR"
    exit 1
fi

# Create target directory structure
mkdir -p "$TARGET_DIR"/{metadata,scenes,furnitures,queries}

# Copy metadata files (excluding index files)
echo "Copying metadata files..."
for file in "$SOURCE_DIR"/metadata/*.json*; do
    if [[ ! $file =~ _index.json$ ]]; then
        cp "$file" "$TARGET_DIR/metadata/"
    fi
done

# Function to process chunks of a specific type
process_chunks() {
    local type=$1
    local src_dir="$SOURCE_DIR/$type"
    local target_dir="$TARGET_DIR/$type"
    
    echo "Processing $type chunks..."
    
    # Check if source directory exists
    if [ ! -d "$src_dir" ]; then
        echo "Warning: Directory not found: $src_dir"
        return
    }
    
    # Count total chunks for progress
    total_chunks=$(ls "$src_dir"/*.tar.gz 2>/dev/null | wc -l)
    if [ "$total_chunks" -eq 0 ]; then
        echo "No chunks found in $src_dir"
        return
    }
    
    # Process each chunk
    current=0
    for chunk in "$src_dir"/*.tar.gz; do
        current=$((current + 1))
        chunk_name=$(basename "$chunk")
        printf "Extracting %s (%d/%d)..." "$chunk_name" "$current" "$total_chunks"
        
        if tar -xzf "$chunk" -C "$target_dir" 2>/dev/null; then
            echo " done"
        else
            echo " failed"
            echo "Warning: Failed to extract $chunk_name"
        fi
    done
}

# Process chunks based on input
if [ -n "$CHUNK_TYPE" ]; then
    case "$CHUNK_TYPE" in
        scenes|furnitures|queries)
            process_chunks "$CHUNK_TYPE"
            ;;
        *)
            echo "Error: Invalid chunk type: $CHUNK_TYPE"
            echo "Valid types are: scenes, furnitures, queries"
            exit 1
            ;;
    esac
else
    # Process all chunk types
    for type in scenes furnitures queries; do
        process_chunks "$type"
    done
fi

# Basic validation
echo -e "\nValidating extracted files..."

# Check scenes
if [ -z "$CHUNK_TYPE" ] || [ "$CHUNK_TYPE" = "scenes" ]; then
    missing_files=0
    for scene_dir in "$TARGET_DIR"/scenes/*; do
        if [ -d "$scene_dir" ]; then
            for required in "image.jpg" "annotation.json"; do
                if [ ! -f "$scene_dir/$required" ]; then
                    echo "Warning: Missing $required in $(basename "$scene_dir")"
                    missing_files=$((missing_files + 1))
                fi
            done
        fi
    done
    echo "Scene validation complete. Missing files: $missing_files"
fi

echo "Dataset uncompression completed!"
echo "Output directory: $TARGET_DIR"