Coder Social home page Coder Social logo

I get this issues:Dimension out of range (expected to be in range of [-2, 1], but got 2) about a-pytorch-tutorial-to-image-captioning HOT 1 CLOSED

Kevinskt avatar Kevinskt commented on June 10, 2024
I get this issues:Dimension out of range (expected to be in range of [-2, 1], but got 2)

from a-pytorch-tutorial-to-image-captioning.

Comments (1)

Kevinskt avatar Kevinskt commented on June 10, 2024

I have solved this problem,
“Dimension out of range (expected to be in range of [-2, 1], but got 2)”
The reason for this issue is that scores was originally a three-dimensional tensor, but after the operation
scores = pack_padded_sequence(scores, decode_lengths, batch_first=True)[0],
it became a two-dimensional vector.

Here are two solutions:
1.Use the pad_packed_sequence function to restore it.
2.Before reducing dimensionality, use unpacked_scores = scores, then: _, preds = torch.max(unpacked_scores, dim=2).
Note: The original code used scores_copy, I replaced it to avoid errors.

from a-pytorch-tutorial-to-image-captioning.

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.