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

RSquare does not work with generators #2873

Open
github-abdellah-elyounsi opened this issue Jul 11, 2024 · 0 comments
Open

RSquare does not work with generators #2873

github-abdellah-elyounsi opened this issue Jul 11, 2024 · 0 comments

Comments

@github-abdellah-elyounsi
Copy link

github-abdellah-elyounsi commented Jul 11, 2024

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 20.04):
  • TensorFlow version and how it was installed (source or binary): 2.12.1 via pip
  • TensorFlow-Addons version and how it was installed (source or binary):latest via pip
  • Python version: 3.10
  • Is GPU used? (yes/no): yes

Describe the bug
RSquare does not work with data generator it returns ValueError: Cannot convert a partially known TensorShape (None,) to a Tensor because y_true for some reason is None, None

If the code compiled without RSquare, mse for example everything works.

Code to reproduce the issue

I have the following code:


class DataGenerator(Sequence):
    def __init__(self, x_set, y_set, batch_size):
        self.x, self.y = x_set, y_set
        self.batch_size = batch_size

    def __len__(self):
        return int(np.ceil(len(self.x[0]) / float(self.batch_size)))

    def __getitem__(self, idx):
        low = idx * self.batch_size
        high = min(low + self.batch_size, len(self.x[0]))
        batch_x = [
            self.x[0].iloc[low : high],
            self.x[1].iloc[low : high],
        ]
        batch_y = self.y.iloc[low : high]
        return batch_x, batch_y


model a simple linear model compiled with metrics = Rsquare() and predicts a probability. Labels are 0 and 1 trained with cross entropy

train_gen = DataGenerator(inputs_train,y_train, batch_size)
val_gen = DataGenerator(inputs_val, y_val, batch_size)
history = model.fit(
        train_gen,
        validation_data=val_gen,
        epochs=1,
        shuffle=True,
        verbose=2,
    )

Other info / logs

This code works with all other metrics.

More logs:
NFO:root:DataGenerator set completed
2024-07-11 13:01:33.025178: I tensorflow/core/common_runtime/executor.cc:1197] [/device:CPU:0] (DEBUG INFO) Executor start aborting (this does not indicate an error and you can ignore this message): INVALID_ARGUMENT: You must feed a value for placeholder tensor 'Placeholder/_0' with dtype int32
[[{{node Placeholder/_0}}]]
Learning rate for epoch 1 is 1.00E-02
y_true (None, None)
y_pred (None, 1)
y_true: Tensor("Cast_2:0", shape=(None, None), dtype=float32)
y_pred: Tensor("model/activation/Sigmoid:0", shape=(None, 1), dtype=float32)

Any idea why ? Thank you !

@github-abdellah-elyounsi github-abdellah-elyounsi changed the title RSquare does not work RSquare does not work with generators Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant