Git Product home page Git Product logo

Comments (4)

yeyupiaoling avatar yeyupiaoling commented on July 17, 2024

这样,要执行两次,第一次是预热。

def infer():
    s = time.time()
    data = load_audio(args.audio_path, mode='infer')
    data = data[np.newaxis, :]
    data = torch.tensor(data, dtype=torch.float32, device=device)
    # 执行预测
    output = model(data)
    result = torch.nn.functional.softmax(output, dim=-1)
    result = result.data.cpu().numpy()
    # 显示图片并输出结果最大的label
    lab = np.argsort(result)[0][-1]
    print(f'音频:{args.audio_path} 的预测结果标签为:{class_labels[lab]}')
    print(time.time() - s)

from audioclassification-pytorch.

SSTato avatar SSTato commented on July 17, 2024

这样,要执行两次,第一次是预热。

def infer():
    s = time.time()
    data = load_audio(args.audio_path, mode='infer')
    data = data[np.newaxis, :]
    data = torch.tensor(data, dtype=torch.float32, device=device)
    # 执行预测
    output = model(data)
    result = torch.nn.functional.softmax(output, dim=-1)
    result = result.data.cpu().numpy()
    # 显示图片并输出结果最大的label
    lab = np.argsort(result)[0][-1]
    print(f'音频:{args.audio_path} 的预测结果标签为:{class_labels[lab]}')
    print(time.time() - s)

时间是1.5104613304138184
执行两次是为什么,因为我多次执行基本都是1.5左右,是不是因为启动也需要时间的原因,如果批预测的话平均时间就低了?不知道我的理解对吗,如果看推理速度的话,应该是计算多个文件预测的平均时间吧

from audioclassification-pytorch.

yeyupiaoling avatar yeyupiaoling commented on July 17, 2024

你的预热是再一个程序里面执行多次吗?
是这样的哦:

if __name__ == '__main__':
    infer()
    infer()
    infer()

from audioclassification-pytorch.

SSTato avatar SSTato commented on July 17, 2024

你的预热是再一个程序里面执行多次吗? 是这样的哦:

if __name__ == '__main__':
    infer()
    infer()
    infer()

sorry,我明白了,确实是预热的原因,时间是0.031914710998535156,很快了,多谢!

from audioclassification-pytorch.

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.