windows and linux path difference of tensorflow

In the case of images in tensorflow,

FIG LICENSE.txt following documents:

Here Insert Picture Description

LICENSE.txt dictionary file generation using the following code:

attributions = (data_root/“LICENSE.txt”).open(encoding=‘utf-8’).readlines()[4:]
attributions = [line.split(’ CC-BY’) for line in attributions]
attributions = dict(attributions)

Such dictionary reads as follows:

attributions[“sunflowers/5923085671_f81dd1cf6f.jpg”]
Out[31]: ’ by Svetoslav Nikolov - https://www.flickr.com/photos/svenikolov/5923085671/\n’

Different windows read the file path backslash.

import random
all_image_paths = list(data_root.glob(’/’))
all_image_paths = [str(path) for path in all_image_paths]
image_path = random.choice(all_image_paths)

image_path
Out[28]: 'C:\Users\zephyr_wang\.keras\datasets\flower_photos\sunflowers\5923085671_f81dd1cf6f.jpg’

image_rel = pathlib.Path(image_path).relative_to(data_root)

image_rel
Out[27]: WindowsPath(‘sunflowers/5923085671_f81dd1cf6f.jpg’)

After transfection into a string, a backslash different

str(image_rel)
Out[38]: ‘sunflowers\5923085671_f81dd1cf6f.jpg’

It does not match the dictionary, attributions [str (image_rel)] being given.
Here Insert Picture Description

Published 21 original articles · won praise 18 · views 1463

Guess you like

Origin blog.csdn.net/zephyr_wang/article/details/102698225