LoginSignup
0
0

More than 1 year has passed since last update.

かぐーる(Windows10、Python3.9)

Last updated at Posted at 2022-02-02

はじめに

クジラ・イルカの識別をやっていこうかなと。

開発環境

  • Windows 10 PC
  • Python 3.9
  • Google Drive (2TB)
  • Google Colaboratory

実装

1.Google Drive上にKaggle/happy-whale-and-dolphinフォルダを作成しておき、マウントしてカレントディレクトリを移動する

import os
from google.colab import drive
drive.mount('/content/drive')
os.chdir("/content/drive/MyDrive/Kaggle/happy-whale-and-dolphin")

2.KaggleのサイトからAccountページのCreate New API Tokenをクリックし、kaggle.jsonをダウンロードする

3.ダウンロードしたkaggle.jsonをGoogle Driveに置いておき、環境変数の設定をする

import json
f = open("/content/drive/MyDrive/kaggle.json", 'r')
json_data = json.load(f) 
os.environ['KAGGLE_USERNAME'] = json_data['username']
os.environ['KAGGLE_KEY'] = json_data['key']

※ファイル選択する方法もある

from google.colab import files

uploaded = files.upload()

for fn in uploaded.keys():
  print('User uploaded file "{name}" with length {length} bytes'.format(
      name=fn, length=len(uploaded[fn])))

!mkdir -p ~/.kaggle/ && mv kaggle.json ~/.kaggle/ && chmod 600 ~/.kaggle/kaggle.json

4.kaggleをインストールして、アップグレード

!pip install kaggle
!pip install --upgrade --force-reinstall --no-deps kaggle

※下記のアップグレードだと、Warning: Looks like you're using an outdated API Version, please consider updating (server 1.5.12 / client 1.5.4)が出て、うまくデータセットがダウンロードできなかった

!pip install kaggle --upgrade

5.データセットをダウンロード

!kaggle competitions download -c happy-whale-and-dolphin
!unzip happy-whale-and-dolphin.zip

結局、Colaboratoryのディスク分しかダウンロードできなそう。。。
image.png

お疲れ様でした。

パソコン版GoogleDriveを使う(失敗)

1.パソコン版GoogleDriveを導入する

2.anaconda promptでkaggle apiをインストール

pip install kaggle

3.Kaggle -> Account -> Create New API Token

ダウンロードしたkaggle.jsonをC:\Users<ユーザー名>.kaggle/の中に置く

(py39) G:\マイドライブ\Happywhale>kaggle competitions download -c happy-whale-and-dolphin
Traceback (most recent call last):
  File "c:\users\good_\anaconda3\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\good_\anaconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\good_\anaconda3\Scripts\kaggle.exe\__main__.py", line 4, in <module>
  File "c:\users\good_\anaconda3\lib\site-packages\kaggle\__init__.py", line 23, in <module>
    api.authenticate()
  File "c:\users\good_\anaconda3\lib\site-packages\kaggle\api\kaggle_api_extended.py", line 164, in authenticate
    raise IOError('Could not find {}. Make sure it\'s located in'
OSError: Could not find kaggle.json. Make sure it's located in C:\Users\good_\.kaggle. Or use the environment method.

4.データセットをGドライブにダウンロードする

kaggle competitions download -c happy-whale-and-dolphin

ダウンロード中。
結局、ローカルドライブの空き容量分しか使えず。。。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0