forked from lindsey98/Phishpedia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.bat
141 lines (120 loc) · 3.67 KB
/
setup.bat
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
@echo off
setlocal enabledelayedexpansion
:: 设置环境名称
set "ENV_NAME=phishpedia"
if not defined ENV_NAME set "ENV_NAME=phishpedia"
:: 设置重试次数
set RETRY_COUNT=3
:: 检查 Conda 是否安装
where conda >nul 2>&1
if %ERRORLEVEL% neq 0 (
call :error_exit "Conda is not installed. Please install Conda and try again."
exit /b 1
)
:: 检查环境是否存在
conda env list | find /i "%ENV_NAME%" >nul
if %ERRORLEVEL% equ 0 (
echo Activating existing Conda environment: %ENV_NAME%
) else (
echo Creating new Conda environment: %ENV_NAME% with Python 3.8
conda create -y -n %ENV_NAME% python=3.8
if %ERRORLEVEL% neq 0 (
call :error_exit "Failed to create Conda environment."
exit /b 1
)
)
:: 激活环境
call conda activate %ENV_NAME%
if %ERRORLEVEL% neq 0 (
call :error_exit "Failed to activate Conda environment."
exit /b 1
)
:: 安装 gdown
call pip show gdown >nul 2>&1
if %ERRORLEVEL% neq 0 (
echo Installing gdown...
pip install gdown
echo %ERRORLEVEL%
@REM if %ERRORLEVEL% neq 0 (
@REM call :error_exit "Failed to install gdown."
@REM exit /b 1
@REM )
)
:: 检查 CUDA 可用性
nvidia-smi >nul 2>&1
if %ERRORLEVEL% equ 0 (
echo CUDA detected. Installing GPU-supported PyTorch and torchvision...
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
pip install git+https://github.com/facebookresearch/detectron2.git
) else (
echo No CUDA detected. Installing CPU-only PyTorch and torchvision...
pip install torch==1.9.0+cpu torchvision==0.10.0+cpu torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
pip install git+https://github.com/facebookresearch/detectron2.git
)
:: 安装依赖
if exist requirements.txt (
echo Installing requirements...
pip install -r requirements.txt
) else (
call :error_exit "requirements.txt not found."
exit /b 1
)
:: 创建模型目录
set "MODELS_DIR=%CD%\models"
if not exist "%MODELS_DIR%" mkdir "%MODELS_DIR%"
cd "%MODELS_DIR%"
:: 下载所有模型文件
call :download_file "1tE2Mu5WC8uqCxei3XqAd7AWaP5JTmVWH" "rcnn_bet365.pth"
call :download_file "1Q6lqjpl4exW7q_dPbComcj0udBMDl8CW" "faster_rcnn.yaml"
call :download_file "1H0Q_DbdKPLFcZee8I14K62qV7TTy7xvS" "resnetv2_rgb_new.pth.tar"
call :download_file "1fr5ZxBKyDiNZ_1B6rRAfZbAHBBoUjZ7I" "expand_targetlist.zip"
call :download_file "1qSdkSSoCYUkZMKs44Rup_1DPBxHnEKl1" "domain_map.pkl"
:: 解压文件
echo Extracting expand_targetlist.zip...
tar -xvzf expand_targetlist.zip
if %ERRORLEVEL% neq 0 (
call :error_exit "Failed to extract expand_targetlist.zip"
exit /b 1
)
rmdir /s /q "__MACOSX"
:: 处理嵌套目录
cd expand_targetlist
if exist "expand_targetlist\" (
echo Moving files from nested directory...
move "expand_targetlist\*" "."
rmdir "expand_targetlist"
)
del .DS_Store
cd ..
echo Installation completed successfully!
endlocal
exit /b 1
:: 错误处理函数
:error_exit
echo Error: %~1
exit /b 1
:: 下载模型文件函数
:download_file
set "file_id=%~1"
set "file_name=%~2"
set "retry_count=0"
:download_retry
if exist "%file_name%" (
echo %file_name% already exists. Skipping download.
goto :eof
)
echo Attempting to download %file_name% ^(Attempt !retry_count! of %RETRY_COUNT%^)
gdown --id "%file_id%" -O "%file_name%"
if %ERRORLEVEL% equ 0 (
echo Successfully downloaded %file_name%
goto :eof
)
set /a retry_count+=1
if !retry_count! lss %RETRY_COUNT% (
echo Retrying download...
timeout /t 2 >nul
goto download_retry
) else (
call :error_exit "Failed to download %file_name% after %RETRY_COUNT% attempts."
exit /b 1
)