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

I am getting Attribute Error, please help me. #94

Open
amitjaisr opened this issue May 25, 2021 · 3 comments
Open

I am getting Attribute Error, please help me. #94

amitjaisr opened this issue May 25, 2021 · 3 comments

Comments

@amitjaisr
Copy link

AttributeError Traceback (most recent call last)
in ()
106 random_labels = to_categorical(random_labels, 6)
107
--> 108 g_loss = adversarial_model.train_on_batch([z_noise2, random_labels], [1] * batch_size)
109
110 print("g_loss:{}".format(g_loss))

3 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py in train_on_batch(self, x, y, sample_weight, class_weight, reset_metrics, return_dict)
1723 iterator = data_adapter.single_batch_iterator(self.distribute_strategy, x,
1724 y, sample_weight,
-> 1725 class_weight)
1726 self.train_function = self.make_train_function()
1727 logs = self.train_function(iterator)

/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/data_adapter.py in single_batch_iterator(strategy, x, y, sample_weight, class_weight)
1511 data = (x, y, sample_weight)
1512
-> 1513 _check_data_cardinality(data)
1514 dataset = dataset_ops.DatasetV2.from_tensors(data)
1515 if class_weight:

/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/data_adapter.py in _check_data_cardinality(data)
1520
1521 def _check_data_cardinality(data):
-> 1522 num_samples = set(int(i.shape[0]) for i in nest.flatten(data))
1523 if len(num_samples) > 1:
1524 msg = "Data cardinality is ambiguous:\n"

/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/data_adapter.py in (.0)
1520
1521 def _check_data_cardinality(data):
-> 1522 num_samples = set(int(i.shape[0]) for i in nest.flatten(data))
1523 if len(num_samples) > 1:
1524 msg = "Data cardinality is ambiguous:\n"

AttributeError: 'int' object has no attribute 'shape'

@amitjaisr
Copy link
Author

Please look into this and help me, I am stuck here.
Also If you want I can share my whole code.

@kailashahirwar
Copy link
Collaborator

Check the type of data before you flatten it. There is a problem with your dataset.

@193947
Copy link

193947 commented Mar 14, 2023

g_loss = adversarial_model.train_on_batch([z_noise2, random_labels], [1] * batch_size)
modify:
g_loss = adversarial_model.train_on_batch([z_noise2, random_labels], np.array([1] * batch_size).reshape(batch_size,1))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants