|
a |
|
b/Download_sam_weights.py |
|
|
1 |
import os |
|
|
2 |
import requests |
|
|
3 |
|
|
|
4 |
# The URL of the file you want to download |
|
|
5 |
url = 'https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth' |
|
|
6 |
|
|
|
7 |
# The path where you want to save the downloaded file |
|
|
8 |
save_path = './models/sam_vit_h_4b8939.pth' |
|
|
9 |
|
|
|
10 |
# Check if the file already exists |
|
|
11 |
if not os.path.exists(save_path): |
|
|
12 |
# Send a GET request to the URL |
|
|
13 |
response = requests.get(url, stream=True) |
|
|
14 |
|
|
|
15 |
# Check if the request was successful |
|
|
16 |
if response.status_code == 200: |
|
|
17 |
# Open the file in write mode |
|
|
18 |
with open(save_path, 'wb') as file: |
|
|
19 |
# Write the contents of the response to the file |
|
|
20 |
for chunk in response.iter_content(chunk_size=1024): |
|
|
21 |
if chunk: |
|
|
22 |
file.write(chunk) |
|
|
23 |
else: |
|
|
24 |
print("The file already exists.") |