File size: 4,645 Bytes
089c099
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
param(
    [string]$BundleRoot = "C:\Users\aryan\Google Drive\My Drive\nes2net_remote_bundle",
    [string]$ProjectRoot = "C:\E\Project\Project B.tech\Multimodal Deepfake Detection",
    [switch]$IncludeDFDataset,
    [switch]$IncludeLA,
    [switch]$IncludeDemoWav,
    [switch]$IncludeInTheWildCheckpoint,
    [switch]$ZipCodeOnly,
    [switch]$DryRun
)

$ErrorActionPreference = "Stop"

function Write-Step {
    param([string]$Message)
    Write-Host "[Bundle] $Message"
}

function Ensure-Dir {
    param([string]$Path)
    if ($DryRun) {
        Write-Step "Would create directory: $Path"
        return
    }
    New-Item -ItemType Directory -Force -Path $Path | Out-Null
}

function Copy-FileSafe {
    param(
        [string]$Source,
        [string]$DestinationDir
    )
    if (-not (Test-Path $Source)) {
        throw "Missing source file: $Source"
    }

    if ($DryRun) {
        Write-Step "Would copy file: $Source -> $DestinationDir"
        return
    }

    Copy-Item -Path $Source -Destination $DestinationDir -Force
}

function Copy-DirSafe {
    param(
        [string]$Source,
        [string]$DestinationParent
    )
    if (-not (Test-Path $Source)) {
        throw "Missing source directory: $Source"
    }

    $leaf = Split-Path -Path $Source -Leaf
    $destination = Join-Path $DestinationParent $leaf

    if ($DryRun) {
        Write-Step "Would copy directory: $Source -> $destination"
        return
    }

    Ensure-Dir $destination

    $robocopyArgs = @(
        $Source,
        $destination,
        "/E",
        "/Z",
        "/R:5",
        "/W:5",
        "/NFL",
        "/NDL",
        "/NJH",
        "/NJS",
        "/NP"
    )

    & robocopy @robocopyArgs | Out-Host
    $robocopyExit = $LASTEXITCODE

    if ($robocopyExit -gt 7) {
        throw "robocopy failed for $Source -> $destination with exit code $robocopyExit"
    }
}

function Zip-CodeFolder {
    param(
        [string]$Source,
        [string]$DestinationZip
    )
    if ($DryRun) {
        Write-Step "Would zip code folder: $Source -> $DestinationZip"
        return
    }

    if (Test-Path $DestinationZip) {
        Remove-Item -Path $DestinationZip -Force
    }

    Compress-Archive -Path $Source -DestinationPath $DestinationZip -Force
}

$codeDir = Join-Path $ProjectRoot "audio_detection\Nes2Net_ASVspoof_ITW"
$checkpointsDir = Join-Path $ProjectRoot "audio_detection\checkpoints"
$audioDataDir = Join-Path $ProjectRoot "data\audio"
$notebookPath = Join-Path $ProjectRoot "notebooks\audio_remote_validation_colab.ipynb"

$bundleCodeDir = Join-Path $BundleRoot "code"
$bundleCheckpointsDir = Join-Path $BundleRoot "checkpoints"
$bundleNotebooksDir = Join-Path $BundleRoot "notebooks"
$bundleAudioDir = Join-Path $BundleRoot "data\audio"

Write-Step "Preparing bundle root: $BundleRoot"
Ensure-Dir $bundleCodeDir
Ensure-Dir $bundleCheckpointsDir
Ensure-Dir $bundleNotebooksDir

if ($IncludeDFDataset -or $IncludeLA -or $IncludeDemoWav) {
    Ensure-Dir $bundleAudioDir
}

Write-Step "Copying code bundle"
Copy-DirSafe -Source $codeDir -DestinationParent $bundleCodeDir

Write-Step "Copying Colab notebook"
Copy-FileSafe -Source $notebookPath -DestinationDir $bundleNotebooksDir

Write-Step "Copying required checkpoints"
Copy-FileSafe -Source (Join-Path $checkpointsDir "xlsr2_300m.pt") -DestinationDir $bundleCheckpointsDir
Copy-FileSafe -Source (Join-Path $checkpointsDir "ASVspoof_2021_wav2vec2_Nes2Net_X_e100_bz12_lr2.5e_07_algo4_avg_ckpt_ep56_60_62_76_95.pth") -DestinationDir $bundleCheckpointsDir

if ($IncludeInTheWildCheckpoint) {
    Write-Step "Copying optional In-the-Wild checkpoint"
    Copy-FileSafe -Source (Join-Path $checkpointsDir "In_the_Wild_wav2vec2_Nes2Net_X_e100_bz12_lr2.5e_07_algo4_seed12345_avg_ckpt_ep59_61_69.pth") -DestinationDir $bundleCheckpointsDir
}

if ($IncludeDFDataset) {
    Write-Step "Copying optional DF dataset"
    Copy-DirSafe -Source (Join-Path $audioDataDir "ASVspoof2021_DF_eval") -DestinationParent $bundleAudioDir
}

if ($IncludeLA) {
    Write-Step "Copying optional LA dataset"
    Copy-DirSafe -Source (Join-Path $audioDataDir "ASVspoof2021_LA_eval") -DestinationParent $bundleAudioDir
}

if ($IncludeDemoWav) {
    Write-Step "Copying optional demo WAV folder"
    Copy-DirSafe -Source (Join-Path $audioDataDir "demo_wav") -DestinationParent $bundleAudioDir
}

if ($ZipCodeOnly) {
    $zipPath = Join-Path $BundleRoot "Nes2Net_ASVspoof_ITW.zip"
    Write-Step "Creating optional code zip"
    Zip-CodeFolder -Source $codeDir -DestinationZip $zipPath
}

Write-Step "Bundle preparation complete."
if ($DryRun) {
    Write-Step "Dry run only. No files were copied."
}