[03e852]: / Download_sam_weights.py

Download this file

25 lines (20 with data), 793 Bytes

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