Я пишу код для чтения изображений в Tensorflow.Я использую этот учебник, чтобы сделать это.Проблема в том, что когда я использую эту команду: tf.data.Dataset.from_tensor_slices((all_image_paths, all_image_labels))
, в консоли вывода отображаются все пути изображений.
Это код, который я использую:
def get_image_info(dir_path, file_url=None, file_name=None, untar=True):
if file_url != None:
dir_path = tf.keras.utils.get_file(fname=file_name, origin=file_url, untar=untar)
data_root = pathlib.Path(dir_path)
all_image_paths = list(data_root.glob('*/*'))
label_names = sorted(item.name for item in data_root.glob('*/') if item.is_dir())
label_dict = dict((name, index) for index, name in enumerate(label_names))
all_image_labels = [label_dict[pathlib.Path(path).parent.name] for path in all_image_paths]
return data_root, label_dict, all_image_paths, all_image_labels
def load_image_dataset(dir_path, file_url=None, file_name=None, untar=True):
def load_and_preprocess_from_path_label(path, label):
return load_and_preprocess_image(path), label
data_root, label_dict, all_image_paths, all_image_labels = get_image_info(dir_path, file_url, file_name, untar)
image_label_ds = tf.data.Dataset.from_tensor_slices((all_image_paths, all_image_labels))
# image_label_ds = ds.map(load_and_preprocess_from_path_label)
return image_label_ds, label_dict
image_label_ds, label_dict= load_image_dataset('', 'https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz', 'flower_photos')
и это часть моего вывода:
, WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/8838914676_8ef4db7f50_n.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/8838975946_f54194894e_m.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/8838983024_5c1a767878_n.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/8892851067_79242a7362_n.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/8904780994_8867d64155_n.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/8908062479_449200a1b4.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/8908097235_c3e746d36e_n.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/9019694597_2d3bbedb17.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/9030467406_05e93ff171_n.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/9048307967_40a164a459_m.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/924782410_94ed7913ca_m.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/9378657435_89fabf13c9_n.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/9444202147_405290415b_n.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/9446982168_06c4d71da3_n.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/9831362123_5aac525a99_n.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/9870557734_88eb3b9e3b_n.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/9947374414_fdf1d0861c_n.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/9947385346_3a8cacea02_n.jpg'), WindowsPath('C:/Users/hajba/.keras/datasets/flower_photos/tulips/9976515506_d496c5e72c.jpg')]. Consider casting elements to a supported type.