google colaboraroryで画像をダウンロードしたいのですが、コードに打ち込んだことのない"true"というエラーが出てしまいます。
これはどこを直せばいいのでしょうか?
ぜひ教えていただけると幸いです
from flickrapi import FlickrAPI from urllib.request import urlretrieve from pprint import pprint import os, time, sys, math from google.colab import drive drive.mount('/content/drive') #APIキーの情報 key = "" secret = "" wait_time= 1 #保存フォルダの指定 animalname = sys.argv[1] savedir = "/content/drive/My Drive/Colab Notebooks/kera_lesson_making_colab_ver/"+animalname #保存フォルダーの作成 if not os.path.exists(savedir): os.makedirs(savedir) flickr = FlickrAPI(key, secret,format= 'parsed-json') result = flickr.photos.search( text = animalname, per_page = 400, media = 'photos', sort = 'relevance', safe_search =1, extras = 'url_q,licence' ) photos =result['photos'] #返り血を表示する。 # pprint(photos) for i , photo in enumerate(photos['photo']): url_q =photo['url_q'] filepath =savedir+'/'+photo['id']+'.jpg' if os.path.exists(filepath):continue urlretrieve(url_q,filepath) time.sleep(wait_time)
これを実行して、マウントすると
Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remount=True).
となり、さらに
!python "/content/drive/My Drive/Colab Notebooks/kera_lesson_making_colab_ver/download.ipynb" milk
これを実行すると
Traceback
1 File "/content/drive/My Drive/Colab Notebooks/kera_lesson_making_colab_ver/download.ipynb", line 1, in <module> 2 {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"download.ipynb","private_outputs":true,"provenance":[],"collapsed_sections":[],"authorship_tag":"ABX9TyOzSOksYsiuZBRiyLvGsUYE"},"kernelspec":{"name":"python3","display_name":"Python 3"},"accelerator":"GPU"},"cells":[{"cell_type":"code","metadata":{"id":"xrL91GdPKNHA"},"source":["from flickrapi import FlickrAPI\n","from urllib.request import urlretrieve\n","from pprint import pprint\n","import os, time, sys, math\n","from google.colab import drive\n","drive.mount('/content/drive')\n","\n","#APIキーの情報\n","\n","key = \"\"\n","secret = \""\n","wait_time= 1\n","\n","#保存フォルダの指定\n","animalname = sys.argv[1]\n","savedir = \"/content/drive/My Drive/Colab Notebooks/kera_lesson_making_colab_ver/\"+animalname\n","\n","#保存フォルダーの作成\n","if not os.path.exists(savedir):\n"," os.makedirs(savedir)\n","\n","flickr = FlickrAPI(key, secret,format= 'parsed-json')\n","result = flickr.photos.search(\n"," text = animalname,\n"," per_page = 400,\n"," media = 'photos',\n"," sort = 'relevance',\n"," safe_search =1,\n"," extras = 'url_q,licence'\n",")\n","\n","photos =result['photos']\n","#返り血を表示する。\n","# pprint(photos)\n","\n","for i , photo in enumerate(photos['photo']):\n"," url_q =photo['url_q']\n"," filepath =savedir+'/'+photo['id']+'.jpg'\n"," if os.path.exists(filepath):continue\n"," urlretrieve(url_q,filepath)\n"," time.sleep(wait_time)\n"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"NOXrM1pwL5xA"},"source":["\n","!python \"/content/drive/My Drive/Colab Notebooks/kera_lesson_making_colab_ver/download.ipynb\" milk"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"LDSUZUtjSCft"},"source":[""],"execution_count":null,"outputs":[]}]} 3NameError: name 'true' is not defined
となってしまいます
(一応key secrt は消させていただきました。)
このtrueはどこから出てくるのでしょうか?
また、googleコラボを用いて画像を取ってくることはできないのでしょうか?
ぜひ、ご回答していただけることを願っております
よろしくお願いします。
[ 2021/02/28 12:00時点の投稿に対する言及]
コード中のコメントにある「#返り血を表示する。」とはどういう意味ですか?
> このtrueはどこから出てくるのでしょうか?
"/content/drive/My Drive/Colab Notebooks/kera_lesson_making_colab_ver/download.ipynb"
をローカルPC内にダウンロードして、テキストエディタで開いたら分かると思います
ダウンロードのやり方は、googleコラボの左上の「ファイル」→「.ipynbをダウンロード」
animalname = sys.argv[1]
を
animalname = 'milk'
に変えて、普通にgoogleコラボで実行してみたら、いかがでしょうか?
jbpb0さん前回から引き続きありがとうございます!!!
animalname = 'milk'
としてみたところ解決できました!!!
ほんとうにありがとうございます!!!
回答1件
あなたの回答
tips
プレビュー