/root/miniconda3/bin/python: can‘t open file ‘/root/autodl-tmp/train.py‘: [Errno 2] No such file

本文讲述了在使用SSH连接autodl服务器时遇到的路径问题,通过重新配置项目路径映射解决了'No such file or directory'错误,详细步骤包括设置路径及确认操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在使用SSH连接autodl服务器时,有时在选择train后,会报出

/root/miniconda3/bin/python: can't open file '/root/autodl-tmp/mian.py': [Errno 2] No such file or d

这样的错。
错误原因:映射路径出错
我亲测有效的解决方法是:重新配置一遍项目的路径映射

如下图所示:我在设置中,又重新配置了一遍一模一样的路径

在这里插入图片描述
配置完成后,我们可以看到路径映射这里,多了一串路径
在这里插入图片描述
点击确定之后,再点击run就可以了

/root/miniconda3/bin/conda run -p /root/miniconda3 --no-capture-output python /root/autodl-tmp/clip-pytorch-main/mdistiller/train.py 使用设备: cuda 训练集: 12516 有效样本, 1 类 验证集: 3130 有效样本 教师模型加载完成,参数量: 149620737 /root/miniconda3/lib/python3.12/site-packages/torch/hub.py:293: UserWarning: You are about to download and run code from an untrusted repository. In a future release, this won&#39;t be allowed. To add the repository to your trusted list, change the command to {calling_fn}(..., trust_repo=False) and a command prompt will appear asking for an explicit confirmation of trust, or load(..., trust_repo=True), which will assume that the prompt is to be answered with &#39;yes&#39;. You can also use load(..., trust_repo=&#39;check&#39;) which will only prompt for confirmation if the repo is not already trusted. This will eventually be the default behaviour warnings.warn( Traceback (most recent call last): File "/root/autodl-tmp/clip-pytorch-main/mdistiller/train.py", line 284, in <module> main() File "/root/autodl-tmp/clip-pytorch-main/mdistiller/train.py", line 208, in main student = torch.hub.load(&#39;apple/ml-mobilevit&#39;, &#39;mobilevit_xxs&#39;) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/miniconda3/lib/python3.12/site-packages/torch/hub.py", line 565, in load repo_or_dir = _get_cache_or_reload(repo_or_dir, force_reload, trust_repo, "load", ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/miniconda3/lib/python3.12/site-packages/torch/hub.py", line 229, in _get_cache_or_reload _validate_not_a_forked_repo(repo_owner, repo_name, ref) File "/root/miniconda3/lib/python3.12/site-packages/torch/hub.py", line 189, in _validate_not_a_forked_repo response = json.loads(_read_url(Request(url, headers=headers))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/miniconda3/lib/python3.12/site-packages/torch/hub.py", line 172, in _read_url with urlopen(url) as r: ^^^^^^^^^^^^ File "/root/miniconda3/lib/python3.12/urllib/request.py", line 215, in urlopen return opener.open(url, data, timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/miniconda3/lib/python3.12/urllib/request.py", line 521, in open response = meth(req, response) ^^^^^^^^^^^^^^^^^^^ File "/root/miniconda3/lib/python3.12/urllib/request.py", line 630, in http_response response = self.parent.error( ^^^^^^^^^^^^^^^^^^ File "/root/miniconda3/lib/python3.12/urllib/request.py", line 559, in error return self._call_chain(*args) ^^^^^^^^^^^^^^^^^^^^^^^ File "/root/miniconda3/lib/python3.12/urllib/request.py", line 492, in _call_chain result = func(*args) ^^^^^^^^^^^ File "/root/miniconda3/lib/python3.12/urllib/request.py", line 639, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 404: Not Found ERROR conda.cli.main_run:execute(125): `conda run python /root/autodl-tmp/clip-pytorch-main/mdistiller/train.py` failed. (See above for error) 进程已结束,退出代码为 1
05-27
### 解决 `torch.hub.load` 加载 MobileViT 模型时的 HTTP 404 错误 当使用 `torch.hub.load` 方法加载来自 GitHub 存储库(如 `apple/ml-mobilevit`)中的模型时,如果出现 HTTP 404 错误,通常是由于以下原因之一引起的: 1. **存储库不可访问**:GitHub 可能暂时屏蔽了对该存储库的请求,或者该存储库已被移除或重命名。 2. **网络连接问题**:用户的网络环境可能存在限制,阻止了对 GitHub 的正常访问。 3. **PyTorch Hub 缓存失效**:有时 PyTorch Hub 的缓存可能会导致加载失败。 #### 替代方案一:离线加载本地 `.pt` 文件 为了避免依赖在线资源,可以将预训练模型下载到本地,并通过加载 `.pt` 文件的方式初始化模型。以下是具体实现方法: ```python import torch # 假设已有一个名为 &#39;mobilevit_xxs.pth&#39; 的本地文件 state_dict = torch.load(&#39;mobilevit_xxs.pth&#39;) # 手动实例化 MobileViT 模型 from mobilevit.models import get_model model = get_model(&#39;xxs&#39;, pretrained=False) # 不加载默认权重 # 将本地状态字典应用到模型中 model.load_state_dict(state_dict, strict=True) model.eval() ``` 此方法绕过了 `torch.hub.load` 对远程仓库的依赖,直接从本地加载模型参数[^1]。 --- #### 替代方案二:克隆存储库并手动导入模块 如果无法通过 `torch.hub.load` 访问存储库,可以选择手动克隆存储库并将其中的 Python 模块作为本地包引入。步骤如下: 1. 克隆存储库至本地: ```bash git clone https://github.com/apple/ml-mobilevit.git ``` 2. 修改工作目录以包含存储库路径: ```python import sys sys.path.append(&#39;/path/to/ml-mobilevit&#39;) # 替换为实际路径 from mobilevit.models import get_model model = get_model(&#39;xxs&#39;, pretrained=False) state_dict = torch.load(&#39;mobilevit_xxs.pth&#39;) model.load_state_dict(state_dict, strict=True) model.eval() ``` 这种方式允许用户完全控制模型的加载过程,而不受网络条件的影响[^2]。 --- #### 替代方案三:切换到其他托管平台获取预训练模型 除了 GitHub 外,还可以尝试从其他公开托管服务(如 Hugging Face Model Hub 或百度网盘)下载 MobileViT 的预训练权重。例如: - **Hugging Face Model Hub**: 移步 [MobileViT 页面](https://huggingface.co/models?search=mobilevit),查找适合的变体并下载其 `.bin` 或 `.pt` 权重文件。 - **百度网盘**: 如果已有他人分享的链接(如引用提到的内容),可以直接下载并按照前述方式加载。 --- ### 总结 针对 `torch.hub.load` 出现的 HTTP 404 错误,建议采取以下措施之一: 1. 离线加载本地 `.pt` 文件; 2. 手动克隆存储库并导入相关模块; 3. 切换到其他托管平台获取预训练模型。 无论哪种方法,均需确保所使用的权重文件与目标模型架构相匹配,以免引发键冲突或其他异常情况。 ---
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值