我正在尝试在自己的图像数据集上使用CNN开发图像分类模型 我知道使用张量流中的现有数据集开发此类模型 但是我正在努力将我的数据集添加到张量流 我已经尝试使用以下代码转换准备图像数据集,并且类型(数据集)为tensorflow.python.data.ops.dataset_ops.DatasetV1Adapter 现在,我想将其添加到tensorflow数据集中,以便可以使用dataset.load_data()轻松加载数据集
有人可以帮助我吗?
在file.csv中,“图像”列包含图像名称,“类”列包含图像的类 我将这些列作为参数传递给tf.constant(),如下面的代码所示。
import pandas as pd
import tensorflow as tf
df = pd.read_csv('file.csv')
filenames = tf.constant(df.Image)
labels = tf.constant(df.Class)
dataset = tf.data.Dataset.from_tensor_slices((filenames, labels))
def _parse_function(filename, label):
image_string = tf.read_file(filename)
image_decoded = tf.image.decode_jpeg(image_string, channels=3)
image = tf.cast(image_decoded, tf.float32)
return image, label
dataset = dataset.map(_parse_function)
dataset = dataset.batch(2)
iterator = dataset.make_one_shot_iterator()
images, labels = iterator.get_next()