將大文件從驅動器下載到 colab (download large file from drive to colab)


問題描述

將大文件從驅動器下載到 colab (download large file from drive to colab)

我有一個指向公共 Google 雲端硬盤託管文件的鏈接:

https://drive.google.com/uc?id=19VsarMcYRNPLTDr6b6ABJyY8JUeBueL8&export=download

以下是適用於不同文件和鏈接的 .sh 腳本:

#!/usr/bin/env bash
function gdrive_download () { # credit to https://github.com/ethanjperez/convince
  CONFIRM=$(wget ‑‑quiet ‑‑save‑cookies /tmp/cookies.txt ‑‑keep‑session‑cookies ‑‑no‑check‑certificate "https://docs.google.com/uc?export=download&id=$1" ‑O‑ | sed ‑rn 's/.*confirm=([0‑9A‑Za‑z_]+).*/\1\n/p')
  wget ‑‑load‑cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$CONFIRM&id=$1" ‑O $2
  rm ‑rf /tmp/cookies.txt
}

mkdir ‑p Models/real‑fixed‑cam Models/real‑hand‑held
gdrive_download 1yiNsSkPYoBZ55fSQ1iwb1io9QL_PcR2i Models/real‑fixed‑cam/netG_epoch_12.pth
gdrive_download 13HckO9fPAKYocdB_CAC5n8uyM3xQ2MpG Models/real‑hand‑held/netG_epoch_12.pth

上面的腳本在 Colab 中被調用:

!wget https://gist.githubusercontent.com/andreyryabtsev/458f7450c630952d1e75e195f94845a0/raw/0b4336ac2a2140ac2313f9966316467e8cd3002a/download.sh
!chmod +x download.sh
!./download.sh

我已經對其進行瞭如下調整以滿足我的需要:

#!/usr/bin/env bash
function gdrive_download () { # credit to https://github.com/ethanjperez/convince
  CONFIRM=$(wget ‑‑quiet ‑‑save‑cookies /tmp/cookies.txt ‑‑keep‑session‑cookies ‑‑no‑check‑certificate "https://docs.google.com/uc?export=download&id=$1" ‑O‑ | sed ‑rn 's/.*confirm=([0‑9A‑Za‑z_]+).*/\1\n/p')
  wget ‑‑load‑cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$CONFIRM&id=$1" ‑O $2
  rm ‑rf /tmp/cookies.txt
}

mkdir ‑p pix2pix/checkpoint
gdrive_download 19VsarMcYRNPLTDr6b6ABJyY8JUeBueL8 pix2pix/checkpoint/weights.zip

上面的代碼被調用colab with:

!wget https://gist.githubusercontent.com/Daryl149/070397c9cb3539f5cd01173f6c44200d/raw/207a76e94e70e6c9334f48c25b4998f4fd1b95e3/download.sh
!chmod +x download.sh
!./download.sh

文件夾已正確創建。但它並沒有將 500mb+ 的 zip 文件下載到 checkpoints 文件夾,而是從下載確認頁面下載了 html。


參考解法

方法 1:

Try this

!gdown 19VsarMcYRNPLTDr6b6ABJyY8JUeBueL8

Then, you can create a new directory with !mkdir or move the weights.zip there.

方法 2:

Based on @korakot's answer, the full working code to achieve the result in Colab is:

!gdown https://drive.google.com/uc?id=19VsarMcYRNPLTDr6b6ABJyY8JUeBueL8
!mkdir /content/Person_remover/pix2pix/checkpoint
import shutil
shutil.move("/content/Person_remover/weights.zip", "/content/Person_remover/pix2pix/checkpoint")

(by DaRealkorakotDaReal)

參考文件

  1. download large file from drive to colab (CC BY‑SA 2.5/3.0/4.0)

#google-colaboratory #google-drive-api #shell






相關問題

如何解決“變量在檢查點可用,但與模型變量的形狀不兼容”? (How to solve "Variable is available in checkpoint, but has an incompatible shape with model variable"?)

Google Colab 上的深度學習:加載大型圖像數據集很長,如何加速這個過程? (Deep learnin on Google Colab: loading large image dataset is very long, how to accelerate the process?)

如果我在硬件加速器中選擇“無”會怎樣? (What does it do if I choose "None" in Hardware Accelerator?)

Google Collab 筆記本是否共享資源? (Do Google Collab notebooks share resources?)

如何在 colab 上運行 gurobi (How to run gurobi on colab)

Python 使用 Selenium 從頁面上的多個鏈接中抓取數據 (Python Using Selenium to scrape data from multiple links on a page)

如何在 Colab 中使用已安裝的 Google Drive 加快解壓縮/讀取文件的速度? (How can I speed up unzipping / reading files with a mounted Google Drive in Colab?)

為什麼當我安裝了 Tensorflow 的所有庫後,會出現無目錄錯誤? (Why do I get a no directory error, when I have installed all the libraries for Tensorflow?)

Tensorboard 可視化不會出現在谷歌協作中 (Tensorboard visualization don't appear in google collab)

警告:此運行時之前已導入以下包:[PIL] 您必須重新啟動運行時才能使用新安裝的版本 (WARNING: The following packages were previously imported in this runtime: [PIL] You must restart the runtime in order to use newly installed versions)

有沒有辦法在 Tensorflow 自定義層(在 TPU 上)中動態 N 次復制張量? (Is there a way for dynamic N-times replication of a tensor in Tensorflow custom layer (on TPU)?)

如何在 googlecolab 中為 python 使用 Soundex()? (How to use Soundex() in googlecolab for python?)







留言討論