Tencent/ncnn

when I use ncnn model to infer some images, for each image, I must create a new extractor? 每次有新输入都必须创建一个新的extractor吗?

Closed this issue · 2 comments

detail | 详细描述 | 詳細な説明

when my infer code like below, the result of each circle is the same.

`def my_test_inference():
torch.manual_seed(0)

with ncnn.Net() as net:
    net.load_param("/home/hejiaqi18/my_projects/ultralytics-8.3.2/runs/train/yolov11s-6cls-warpdataset-18k/weights/best_ncnn_model/model.ncnn.param")
    net.load_model("/home/hejiaqi18/my_projects/ultralytics-8.3.2/runs/train/yolov11s-6cls-warpdataset-18k/weights/best_ncnn_model/model.ncnn.bin")

    with net.create_extractor() as ex:
        for i in range(10):
            in0 = torch.rand(1, 3, 640, 640, dtype=torch.float)
            ex.input("in0", ncnn.Mat(in0.squeeze(0).numpy()).clone())
            _, out0 = ex.extract("out0")
            print(out0)`

if I want to get correct results of these inputs, I must create extractor for each input. If it is reasonable??

ex.input的输入有没有什么办法能覆盖上一次的呢?比如extractor有没有什么clear的方法?必须每次有新输入都创建一个新的extractor吗?感觉有点耗和加耗费资源?
另外请问ncnn模型推理的过程实际上是不是就是ex.extract这行代码呢?

是的亲,extractor是用完就扔的,你说的资源本体其实是ncnn::Net

nihui commented

新输入应当使用新的 extractor
创建 extractor 不耗时