How to feed in images into the model Keras
up vote
0
down vote
favorite
I have a dataset for the self-driving car. My X
values are the names of the images. Example would be
array([['img_2.png'],
['img_3.png'],
['img_4.png'],
...,
['img_6405.png'],
['img_6406.png'],
['img_6407.png']], dtype=object)
I found out that model performs good if we have some kind of batch_generator
. I found that template code.
def batch_generator(image_paths, steering_ang, batch_size, istraining):
while True:
batch_img =
batch_steering =
for i in range(batch_size):
random_index = random.randint(0, len(image_paths) - 1)
if istraining:
im = random_augment(image_paths[random_index])
steering = steering_ang[random_index]
else:
im = mpimg.imread(image_paths[random_index])
steering = steering_ang[random_index]
im = img_preprocess(im)
batch_img.append(im)
batch_steering.append(steering)
yield (np.asarray(batch_img), np.asarray(batch_steering))
I changed this function to for my use but when i apply it.
x_train_gen, y_train_gen = next(batch_generator(X_train, y_train, 1, 1))
x_valid_gen, y_valid_gen = next(batch_generator(X_valid, y_valid, 1, 0))
I get the following error TypeError: Object does not appear to be a 8-bit string path or a Python file-like object
. I understand the error, image is not an array but a string. How can i convert string of the image path to the array
python image-processing keras neural-network deep-learning
add a comment |
up vote
0
down vote
favorite
I have a dataset for the self-driving car. My X
values are the names of the images. Example would be
array([['img_2.png'],
['img_3.png'],
['img_4.png'],
...,
['img_6405.png'],
['img_6406.png'],
['img_6407.png']], dtype=object)
I found out that model performs good if we have some kind of batch_generator
. I found that template code.
def batch_generator(image_paths, steering_ang, batch_size, istraining):
while True:
batch_img =
batch_steering =
for i in range(batch_size):
random_index = random.randint(0, len(image_paths) - 1)
if istraining:
im = random_augment(image_paths[random_index])
steering = steering_ang[random_index]
else:
im = mpimg.imread(image_paths[random_index])
steering = steering_ang[random_index]
im = img_preprocess(im)
batch_img.append(im)
batch_steering.append(steering)
yield (np.asarray(batch_img), np.asarray(batch_steering))
I changed this function to for my use but when i apply it.
x_train_gen, y_train_gen = next(batch_generator(X_train, y_train, 1, 1))
x_valid_gen, y_valid_gen = next(batch_generator(X_valid, y_valid, 1, 0))
I get the following error TypeError: Object does not appear to be a 8-bit string path or a Python file-like object
. I understand the error, image is not an array but a string. How can i convert string of the image path to the array
python image-processing keras neural-network deep-learning
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a dataset for the self-driving car. My X
values are the names of the images. Example would be
array([['img_2.png'],
['img_3.png'],
['img_4.png'],
...,
['img_6405.png'],
['img_6406.png'],
['img_6407.png']], dtype=object)
I found out that model performs good if we have some kind of batch_generator
. I found that template code.
def batch_generator(image_paths, steering_ang, batch_size, istraining):
while True:
batch_img =
batch_steering =
for i in range(batch_size):
random_index = random.randint(0, len(image_paths) - 1)
if istraining:
im = random_augment(image_paths[random_index])
steering = steering_ang[random_index]
else:
im = mpimg.imread(image_paths[random_index])
steering = steering_ang[random_index]
im = img_preprocess(im)
batch_img.append(im)
batch_steering.append(steering)
yield (np.asarray(batch_img), np.asarray(batch_steering))
I changed this function to for my use but when i apply it.
x_train_gen, y_train_gen = next(batch_generator(X_train, y_train, 1, 1))
x_valid_gen, y_valid_gen = next(batch_generator(X_valid, y_valid, 1, 0))
I get the following error TypeError: Object does not appear to be a 8-bit string path or a Python file-like object
. I understand the error, image is not an array but a string. How can i convert string of the image path to the array
python image-processing keras neural-network deep-learning
I have a dataset for the self-driving car. My X
values are the names of the images. Example would be
array([['img_2.png'],
['img_3.png'],
['img_4.png'],
...,
['img_6405.png'],
['img_6406.png'],
['img_6407.png']], dtype=object)
I found out that model performs good if we have some kind of batch_generator
. I found that template code.
def batch_generator(image_paths, steering_ang, batch_size, istraining):
while True:
batch_img =
batch_steering =
for i in range(batch_size):
random_index = random.randint(0, len(image_paths) - 1)
if istraining:
im = random_augment(image_paths[random_index])
steering = steering_ang[random_index]
else:
im = mpimg.imread(image_paths[random_index])
steering = steering_ang[random_index]
im = img_preprocess(im)
batch_img.append(im)
batch_steering.append(steering)
yield (np.asarray(batch_img), np.asarray(batch_steering))
I changed this function to for my use but when i apply it.
x_train_gen, y_train_gen = next(batch_generator(X_train, y_train, 1, 1))
x_valid_gen, y_valid_gen = next(batch_generator(X_valid, y_valid, 1, 0))
I get the following error TypeError: Object does not appear to be a 8-bit string path or a Python file-like object
. I understand the error, image is not an array but a string. How can i convert string of the image path to the array
python image-processing keras neural-network deep-learning
python image-processing keras neural-network deep-learning
asked Nov 8 at 2:46
user9900027
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I don't know what you're doing in the img_preprocess()
function but from what I see there are 2 possible problems:
You have to append the path to the image to the image name:
path_to_image = path_to_image_dir + '/' + image
You have to actually open the image to get it's array. You can use Pillow or OpenCV:
PIL.Image.open(path_to_image)
orcv2.imread(path_to_image)
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I don't know what you're doing in the img_preprocess()
function but from what I see there are 2 possible problems:
You have to append the path to the image to the image name:
path_to_image = path_to_image_dir + '/' + image
You have to actually open the image to get it's array. You can use Pillow or OpenCV:
PIL.Image.open(path_to_image)
orcv2.imread(path_to_image)
add a comment |
up vote
0
down vote
I don't know what you're doing in the img_preprocess()
function but from what I see there are 2 possible problems:
You have to append the path to the image to the image name:
path_to_image = path_to_image_dir + '/' + image
You have to actually open the image to get it's array. You can use Pillow or OpenCV:
PIL.Image.open(path_to_image)
orcv2.imread(path_to_image)
add a comment |
up vote
0
down vote
up vote
0
down vote
I don't know what you're doing in the img_preprocess()
function but from what I see there are 2 possible problems:
You have to append the path to the image to the image name:
path_to_image = path_to_image_dir + '/' + image
You have to actually open the image to get it's array. You can use Pillow or OpenCV:
PIL.Image.open(path_to_image)
orcv2.imread(path_to_image)
I don't know what you're doing in the img_preprocess()
function but from what I see there are 2 possible problems:
You have to append the path to the image to the image name:
path_to_image = path_to_image_dir + '/' + image
You have to actually open the image to get it's array. You can use Pillow or OpenCV:
PIL.Image.open(path_to_image)
orcv2.imread(path_to_image)
answered Nov 8 at 8:01
Novak
67249
67249
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53200839%2fhow-to-feed-in-images-into-the-model-keras%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown