Giter Club home page Giter Club logo

Comments (8)

coder-monishr avatar coder-monishr commented on June 27, 2024

@sachinprasadhs help me out

from keras.

sachinprasadhs avatar sachinprasadhs commented on June 27, 2024

Could you please provide reproducible code in a colab Gist to understand more on the issue. Thanks!

from keras.

coder-monishr avatar coder-monishr commented on June 27, 2024

@sachinprasadhs yeaa

https://colab.research.google.com/drive/1QyLNRMwOhuMpZ_4_eJ5m3pKh2Np_wG7g?usp=sharing

from keras.

sachinprasadhs avatar sachinprasadhs commented on June 27, 2024

You are restricting the input_shape for each convolution operation to be 128,128,3, which does not fit to the actual data size which you are passing which is 256,256,3, replacing your code with below code should work.

from keras.layers import Dense, Conv2D, MaxPool2D, Flatten
from keras.models import Sequential

model = Sequential()

model.add(Conv2D(filters=32, kernel_size=3, padding="same", activation="relu",input_shape=[256,256,3]))
model.add(Conv2D(filters=32, kernel_size=3, padding="same", activation="relu"))
model.add(MaxPool2D(pool_size=2,strides=2))

model.add(Conv2D(filters=64, kernel_size=3, padding="same", activation="relu"))
model.add(Conv2D(filters=64, kernel_size=3, padding="same", activation="relu"))
model.add(MaxPool2D(pool_size=2,strides=2))


model.add(Conv2D(filters=128, kernel_size=3, padding="same", activation="relu"))
model.add(Conv2D(filters=128, kernel_size=3, padding="same", activation="relu"))
model.add(MaxPool2D(pool_size=2,strides=2))

model.add(Conv2D(filters=256, kernel_size=3, padding="same", activation="relu"))
model.add(Conv2D(filters=256, kernel_size=3, padding="same", activation="relu"))
model.add(MaxPool2D(pool_size=2,strides=2))

model.add(Flatten())

model.add(Dense(units = 1024, activation="relu"))

model.add(Dense(units = 1024, activation="relu"))

model.add(Dense(units = 38, activation="softmax"))

model.compile(optimizer = "adam", loss ='categorical_crossentropy', metrics=['accuracy'])

from keras.

coder-monishr avatar coder-monishr commented on June 27, 2024

history = model.fit(x=training_set, validation_data=validation_set, epochs=10)

ValueError Traceback (most recent call last)
Cell In[12], line 1
----> 1 history = model.fit(x=training_set, validation_data=validation_set, epochs=10)

File /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/keras/src/utils/traceback_utils.py:123, in filter_traceback..error_handler(*args, **kwargs)
120 filtered_tb = _process_traceback_frames(e.traceback)
121 # To get the full stack trace, call:
122 # keras.config.disable_traceback_filtering()
--> 123 raise e.with_traceback(filtered_tb) from None
124 finally:
125 del filtered_tb

File /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/keras/src/backend/tensorflow/nn.py:546, in categorical_crossentropy(target, output, from_logits, axis)
540 raise ValueError(
541 "Arguments target and output must be at least rank 1. "
542 "Received: "
543 f"target.shape={target.shape}, output.shape={output.shape}"
544 )
545 if len(target.shape) != len(output.shape):
--> 546 raise ValueError(
547 "Arguments target and output must have the same rank "
548 "(ndim). Received: "
549 f"target.shape={target.shape}, output.shape={output.shape}"
550 )
551 for e1, e2 in zip(target.shape, output.shape):
552 if e1 is not None and e2 is not None and e1 != e2:

ValueError: Arguments target and output must have the same rank (ndim). Received: target.shape=(None,), output.shape=(None, 38)

still i get the error dude! :(

from keras.

sachinprasadhs avatar sachinprasadhs commented on June 27, 2024

It is basically the number of classes you are using, if the data is a binary classification then you need to change the output layer to something like model.add(Dense(units = 1, activation="sigmoid"))

from keras.

coder-monishr avatar coder-monishr commented on June 27, 2024

Thank you so much bro solved

from keras.

google-ml-butler avatar google-ml-butler commented on June 27, 2024

Are you satisfied with the resolution of your issue?
Yes
No

from keras.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.