本站资源收集于互联网,不提供软件存储服务,每天免费更新优质的软件以及学习资源!

如何在GoogleColab上运行Samurai

网络教程 app 1℃

如何在GoogleColab上运行Samurai

我的原始帖子
baxin.netlify.app/how-to-run-samurai-on-google-colab/

什么是武士?samurai:采用运动感知内存的零镜头视觉跟踪的分段任意模型要求google colab 的 google 帐户抱脸账号下载数据如何在 google colab 上运行 samurai步骤 0. 获取 hugging face 令牌并将其添加到您的环境变量中

我们需要访问 hugging face 才能下载数据。

如果您不知道如何获取拥抱脸令牌,请参阅此页面。
另外,如果您不知道如何将 hugging face 令牌添加到环境变量中,请查看这篇文章。

步骤 1. 更改默认运行时

要在 google colab 上运行 samurai,我们需要将默认运行时更改为 gpu。
我们需要使用 t4(免费 gpu)。

步骤 2. 安装软件包

!pip install matplotlib==3.7 tikzplotlib jpeg4py opencv-python lmdb pandas scipy loguru

步骤 3. 克隆 samurai 存储库

!git clone github./yangchris11/samurai.git

步骤 4. 安装 sam2

%cd samurai/sam2!pip install -e .!pip install -e ".[notebooks]"

步骤 5. 下载检查点

%cd /content/samurai/sam2/checkpoints!./download_ckpts.sh && %cd ..

步骤 6. 从 hugging face 下载数据

在这一部分中,我们将使用 python 脚本来设置 samurai repo 在数据准备部分中提到的数据。
github./yangchris11/samurai?tab=readme-ov-file#data-preparation

我们将使用的数据是l-lt/lasot

在本例中,我们将下载 cat 数据集,因此如果您想尝试其他数据集,可以相应地更改代码。

import os# define the data directorydata_directory = ‘/content/samurai/data/lasot’# create the data directory if it does not existtry: os.makedirs(data_directory, exist_ok=true) print(f"directory ‘{data_directory}’ created successfully or already exists.")except oserror as error: print(f"error creating directory ‘{data_directory}’: {error}")# define the content to be written to the filecontent = ”’cat-1cat-20”’# define the file pathfile_path = os.path.join(data_directory, ‘testing_set.txt’)# write the content to the filetry: with open(file_path, ‘w’) as f: f.write(content) print(f"content written to file ‘{file_path}’ successfully.")except ioerror as error: print(f"error writing to file ‘{file_path}’: {error}")# print the file pathprint(f’file path: {file_path}’)

import osfrom huggingface_hub import hf_hub_downloadimport zipfileimport shutildef download_and_extract(base_dir="/content/samurai/data"): try: # create lasot and cat directories lasot_dir = os.path.join(base_dir, "lasot") cat_dir = os.path.join(lasot_dir, "cat") os.makedirs(cat_dir, exist_ok=true) # create directory to save the zip file zip_dir = os.path.join(base_dir, "zips") os.makedirs(zip_dir, exist_ok=true) print("downloading dataset…") zip_path = hf_hub_download(repo_id="l-lt/lasot",filename="cat.zip",repo_type="dataset",local_dir=zip_dir ) print(f"downloaded to: {zip_path}") # extract zip file to cat directory print("extracting zip file to cat directory…") with zipfile.zipfile(zip_path, ‘r’) as zip_ref:zip_ref.extractall(cat_dir) print("created directory structure:") print("lasot/") print("└── cat/") # display the first few cat folders for item in sorted(os.listdir(cat_dir))[:6]:print(f" ├── {item}/") print(" └── …") return lasot_dir except exception as e: print(f"an error occurred: {str(e)}") return noneif __name__ == "__main__": extract_path = download_and_extract() if extract_path: print("download and extraction pleted successfully!") else: print("download and extraction failed.")

步骤 7. 推理

最后一步是运行 samurai 推理。
推理需要一段时间。

%cd /content/samurai!python scripts/main_inference.py

如果一切顺利,您应该看到以下输出:

所有代码都可以在此 github 存储库中获取。

如果您喜欢这篇文章,请在 github 上给它一个星。

以上就是如何在 Google Colab 上运行 Samurai的详细内容,更多请关注范的资源库其它相关文章!

转载请注明:范的资源库 » 如何在GoogleColab上运行Samurai

喜欢 (0)