问题描述
总的来说,我是 TensorFlow 和 Python 的初学者,因此非常感谢您的帮助。我正在关注 tensorflow 的 this tutorial,只是使用我自己的数据。
所以我试图从我上传到谷歌驱动器的文件夹中获得的链接下载我自己的数据。然后我将在图像分类器模型中使用该数据。但是,我开始看到图像被下载,它说:
dataset_url_training = "https://drive.google.com/drive/folders/genericid?usp=sharing"
data_dir_training = tf.keras.utils.get_file('flower_photos',origin=dataset_url_training,untar=True)
data_dir_training = pathlib.Path(data_dir_training)
从 https://drive.google.com/drive/folders/genericid?usp=sharing 下载数据
106496/未知 - 2s 14us/步
然后它就停止了。当我尝试使用以下代码时:
print(image_count)
输出吐出:0
我真的很困惑,我不知道该怎么办。一些建议是制作一个 zip 文件 url,但这仅适用于单个文件,不适用于像我这样的整个文件夹。此外,据我所知,Google Drive 不允许您获取 zip 文件的链接,只能获取用于共享的链接(为了澄清,它们是我自己的文件)。
谢谢。
编辑 1:只是想明确一点:我不是在寻找路径。我正在寻找一个 URL,因此使用了一个目录。我也试过使用。 zip 文件的链接,但我收到了与以前相同的错误消息。
解决方法
当您想在 colab 中使用来自 google drive 的文件时,您可以将我们的驱动器挂载到 colab。
Starting tests for method = print
Starting all threads
a = 1
a = 2
a = 1
a = 1
All threads finished in 3.0s <<<<< Note: Should be 3.0s because it should run t1 and t2,then t3,then t4
Starting tests for method = print_get
Starting all threads
get_a = 1
get_a = 2
get_a = 1
a = 1
All threads finished in 3.0s <<<<< Note: Should be 3.0s because it should run t1 and t2,then t4 (or could allow t4 to run at same time as t1 and t2)
Starting tests for method = reentrant_print
Starting all threads
a = 1: i = 0
a = 2: i = 0
a = 1: i = 1
a = 2: i = 1
a = 1: i = 2
a = 2: i = 2
a = 1: i = 3
a = 2: i = 3
a = 1: i = 0 <<< Note: From ~here it should be only t3 running
a = 1: i = 1
a = 1: i = 2
a = 1: i = 3
All threads finished in 4.0s <<<<< Note: Should be 4.0s because it should run t1 and t2,then t4
你可以从谷歌驱动器打开文件。 例如,您的文件位于主驱动器页面上的“文件夹”目录中:
from google.colab import drive
drive.mount('/content/gdrive')
编辑/添加:
为了更清楚,你从教程中更改了这部分
path = "gdrive/My Drive/folder/flower_photos"
到这里
import pathlib
dataset_url = "https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz"
data_dir = tf.keras.utils.get_file('flower_photos',origin=dataset_url,untar=True)
data_dir = pathlib.Path(data_dir)