Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number of ways to split should evenly divide the split dimension #7

Open
tomersein opened this issue Jul 12, 2021 · 1 comment
Open
Assignees
Labels
help wanted Extra attention is needed

Comments

@tomersein
Copy link

Hello,

I'm trying to use the layer, and I'm facing the below error:

batch_size = 128
epochs = 5

model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])
model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, validation_split=0.1)
InvalidArgumentError:  Number of ways to split should evenly divide the split dimension, but got split_dim 0 (size = 29) and num_split 4
	 [[node sequential_1/masksembles2d/split (defined at /usr/local/lib/python3.7/dist-packages/tensorflow_core/python/framework/ops.py:1751) ]] [Op:__inference_distributed_function_14069]

My Network looks like this:

model = keras.Sequential(
    [
        keras.Input(shape=input_shape),
        layers.Conv2D(32, kernel_size=(3, 3), activation="elu"),
        Masksembles2D(4, 2.0), # adding Masksembles2D
        layers.MaxPooling2D(pool_size=(2, 2)),
     
        layers.Conv2D(64, kernel_size=(3, 3), activation="elu"),
        Masksembles2D(4, 2.0), # adding Masksembles2D
        layers.MaxPooling2D(pool_size=(2, 2)),
     
        layers.Flatten(),
        Masksembles1D(4, 2.), # adding Masksembles1D
        layers.Dense(num_classes, activation="softmax"),
    ]
)

model.summary()

My amount of data is 1170 records of train, and 0.1 to the validation.

What should I notice before using this model?

Thanks.

@nikitadurasov nikitadurasov self-assigned this Jul 12, 2021
@nikitadurasov nikitadurasov added the help wanted Extra attention is needed label Jul 12, 2021
@nikitadurasov
Copy link
Owner

Hey Tomer,

I think the problem is that the last training (or validation) batch of your data doesn't actually have 128 samples inside but only 29 (check https://www.tensorflow.org/api_docs/python/tf/data/Dataset, drop_remainder argument).

The current implementation assumes that every batch has a number of samples that are divisible by the number of masks.

A possible workaround is to create tf dataset with drop_remainder option turned on or just check that number of training (and validation) samples is divisible by 4.

  • I think I can try to patch the current implementation so it would work in your case too but I need some time for it.

Best,
Nikita

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants