Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to solve this problem?

See original GitHub issue

Issue Description

Traceback (most recent call last):
  File "", line 142, in <module>
  File "C:\Users\Gepeng-Ji\Anaconda3\envs\keras\lib\site-packages\keras\legacy\", line 91, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\Gepeng-Ji\Anaconda3\envs\keras\lib\site-packages\keras\engine\", line 1418, in fit_generator
  File "C:\Users\Gepeng-Ji\Anaconda3\envs\keras\lib\site-packages\keras\engine\", line 144, in fit_generator
    val_x, val_y, val_sample_weight)
  File "C:\Users\Gepeng-Ji\Anaconda3\envs\keras\lib\site-packages\keras\engine\", line 751, in _standardize_user_data
  File "C:\Users\Gepeng-Ji\Anaconda3\envs\keras\lib\site-packages\keras\engine\", line 128, in standardize_input_data
    'with shape ' + str(data_shape))
ValueError: Error when checking input: expected input_2 to have 2 dimensions, but got array with shape (78, 2, 2)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

4uiiurz1commented, Apr 26, 2019

It’s because that labels are one-hot encoded twice. Please try to remove following line:

labels = np_utils.to_categorical(labels, 2)
4uiiurz1commented, Apr 26, 2019

ImageDataGenerator doesn’t support the tuple ([X_train, y_train], y_train)… Please try following code:

class MyImageDataGenerator:
    def __init__(self):
        self.datagen = ImageDataGenerator(rotation_range=20, zoom_range=0.15, brightness_range=[0.5, 1.5],
                         width_shift_range=0.2, height_shift_range=0.2,
                         shear_range=0.15, horizontal_flip=True, fill_mode="nearest")

    def flow(self, x, y=None, batch_size=32, shuffle=True, sample_weight=None,
             seed=None, save_to_dir=None, save_prefix='', save_format='png', subset=None):
        batches = self.datagen.flow(x, y, batch_size, shuffle, sample_weight,
                               seed, save_to_dir, save_prefix, save_format, subset)

        while True:
            x_batch, y_batch = next(batches)

            yield [x_batch, y_batch], y_batch

aug = MyImageDataGenerator()

H = model.fit_generator(aug.flow(trainX, trainY, batch_size=BS),
                        validation_data=([testX, testY], testY), steps_per_epoch=len(trainX) // BS,
Read more comments on GitHub >

github_iconTop Results From Across the Web

Solve - Step-by-Step Math Problem Solver
QuickMath allows students to get instant solutions to all kinds of math problems, from algebra and equation solving right through to calculus and...
Read more >
How to Solve Problems - Harvard Business Review
First, map out what you remember from each step of your problem-solving. Were all of you on the same page at each stage?...
Read more >
3 Ways to Solve a Problem - wikiHow
1. Define the problem. Find the real problem, not just the symptoms that result from the problem. When defining the problem, do not...
Read more >
11 Brilliant Problem-Solving Techniques Nobody Taught You
All you need to do is ask the question “Why” five times. Start with the problem at hand and ask why it happened,...
Read more >
What is Problem Solving? Steps, Process & Techniques - ASQ
The Problem-Solving Process · 1. Define the problem. Differentiate fact from opinion; Specify underlying causes · 2. Generate alternative solutions. Postpone ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found