statistics in vBulletin
  1. This site is not associated with any agent or consultant and colleges/universities. Views & Opinions expressed here are solely author's comment and is not responsible for them. Please don't make derogatory or abusive remarks against anyone.
  2. Prepare for GMAT, CAT, IIT, PMT & Other Entrance Exams. Post your questions and get answers. Collaborate, Learn & Grow.
    Dismiss Notice
  3. Hi Please download our Android App and enjoy the benefit of this forum on your smartphone. Download in Playstore
    Dismiss Notice
  4. Find Best Colleges in your Area, review them and share feedback.
    Dismiss Notice

module 'tensorflow._api.v1.keras.losses' has no attribute 'SparseCategoricalCrossentropy'

Discussion in 'Artificial Intelligence & Machine Learning' started by bharose, Feb 6, 2021.

  1. bharose

    bharose New Member

    I am building a CNN model with tensorflow and keras.

    I am running following code and getting error-

    module 'tensorflow._api.v1.keras.losses' has no attribute 'SparseCategoricalCrossentropy'

    Code is
    history =, train_labels, epochs=10,
                        validation_data=(test_images, test_labels))
    Response is

    AttributeError                            Traceback (most recent call last)
    <ipython-input-11-fd9ae10ce238> in <module>
          1 model.compile(optimizer='adam',
    ----> 2               loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
          3               metrics=['accuracy'])
          5 history =, train_labels, epochs=10,
    AttributeError: module 'tensorflow._api.v1.keras.losses' has no attribute 'SparseCategoricalCrossentropy'

Share This Page