Issue
I want to use this Pix2Pix Tutorials but using my own dataset. My dataset Is located in my Google Drive, in a folder named facePictues. Inside of that folder I have 151 subfolders whose names are 1 - 151. Inside of these folders are two images: one image is a .jpg which is a real image of a Model's face and The other image is a .png that is a comic book style drawing of that Model's face.
I need to load my data set from my Google Drive and divided into two different dataset tensors one for Training and Testing the Pix2Pix model and then separate my real face images from the drawing face label images.
So I can then Hopefully follow the tutorial.
Here is my code:
all_image_paths = glob.glob(str(data_dir/'*/*'))
all_image_paths = np.array([pathlib.Path(path)for path in all_image_paths])
print("Total images: ", len(all_image_paths))
train_dataset, test_dataset = train_test_split(all_image_paths, test_size=0.2)
print("Train dataset size: ", len(train_dataset))
print("Test dataset size: ", len(test_dataset))
def load_image(dataset):
input_image, target_image = imageio.imread(dataset), imageio.imread(dataset)
input_image = np.array(PIL.Image.fromarray(input_image).resize((256, 256)))
target_image = np.array(PIL.Image.fromarray(target_image).resize((256, 256)))
input_image = (input_image - 127.5) / 127.5
target_image = (target_image - 127.5) / 127.5
input_image = np.expand_dims(input_image, axis=0)
target_image = np.expand_dims(target_image, axis=0)
return input_image, target_image
input_image, target_image = load_image(train_dataset)
display.display(input_image)
display.display(target_image)
I am getting this error :
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-13-ca46c378edd4> in <module>
----> 1 input_image, target_image = load_image(all_image_paths)
2 display.display(input_image)
3 display.display(target_image)
4 frames
/usr/local/lib/python3.7/dist-packages/imageio/core/request.py in _parse_uri(self, uri)
220 if len(uri_r) > 60:
221 uri_r = uri_r[:57] + "..."
--> 222 raise IOError("Cannot understand given URI: %s." % uri_r)
223
224 # Check if this is supported
OSError: Cannot understand given URI: array([PosixPath('gdrive/My
Drive/DrawingDataSet/FacePict....
CODE Update:
def load_image(image_file):
input_image, target_image = imageio.imread(image_file),
imageio.imread(image_file)
input_image =
np.array(PIL.Image.fromarray(input_image).resize((256, 256)))
target_image =
np.array(PIL.Image.fromarray(target_image).resize((256, 256)))
input_image = (input_image - 127.5) / 127.5
target_image = (target_image - 127.5) / 127.5
input_image = np.expand_dims(input_image, axis=0)
target_image = np.expand_dims(target_image, axis=0)
return input_image, target_image
real_image, drawing_image = load_image(train_dataset[0])
RealDataSet = tf.constant(real_image);
print(RealDataSet)
Solution
If you want to get a list of paths you have to do this:
[pathlib.Path(path) for path in all_image_paths]
Instead of:
np.array([pathlib.Path(path)for path in all_image_paths])
With your code you are basically creating a numpy array of a list of strings, which is what your error is complaining about.
Also you should pass a single image to your load_image
function for it to work, e.g. the first image of your dataset:
input_image, target_image = load_image(train_dataset[0])
Answered By - ClaudiaR
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.