jupyter-notebook - 在 google collab 中上传带有标签的图像
问题描述
我在 google collab 中使用 jupyter notebook。我的训练数据集如下所示:
/data/label1/img1.jpeg
.
.
.
/data/label2/img90.jpeg
我想导入这样的数据集。我尝试过的事情
第1步:
!pip install -U -q PyDrive
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
from os import walk
import os
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
第2步:
# 1. Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
第 3 步
file_to_download = os.path.expanduser('./data/')
file_list = drive.ListFile(
{'q': 'id_of_the_data_directory'})
不知道下一步如何进行。该文件夹data
是我在驱动器中的协作笔记本文件夹。我想阅读图像和标签。为了做同样的事情,我正在使用代码:
filename_queue=tf.train.string_input_producer(tf.train.match_filenames_once('data/*/*.jpeg'))
image_reader=tf.WholeFileReader()
key,image_file=image_reader.read(filename_queue)
#key is the entire path to the jpeg file and we need only the subfolder as the label
S = tf.string_split([key],'\/')
length = tf.cast(S.dense_shape[1],tf.int32)
label = S.values[length-tf.constant(2,dtype=tf.int32)]
label = tf.string_to_number(label,out_type=tf.int32)
#decode the image
image=tf.image.decode_jpeg(image_file)
#then code to place labels and folders in corresponding arrays
解决方案
您应该以递归方式上传数据集。这是有关如何将数据集从 Google Drive 上传到 Colab 的示例
推荐阅读
- angular - 行的 Ag-Grid DOM
- spring - 在 spring 中覆盖或更改执行器配置
- ios - UIView 相对于拍摄照片的位置
- excel - 使用 VBA 函数划分矩阵
- mysql - 一个 mySQL 查询来检查一个选项,如果不是真的,另一个选项?
- migration - 使用 pg_dump 和 psql 时模式不存在错误
- docker - Compute Engine、重置或停止+启动
- django - 模板中的图标不显示-Bootstrap 4,Django(添加amazon s3后)
- java - NetBeans 8.2 安装程序未找到 Java SE 开发工具包 (JDK)
- c++ - 将多个文件传递给 C/C++ 编译器是否允许过程间优化?