PaddlePaddle / PaddleDetection

Object Detection toolkit based on PaddlePaddle. It supports object detection, instance segmentation, multiple object tracking and real-time multi-person keypoint detection.
Apache License 2.0
12.83k stars 2.89k forks source link

能否对test_feed.dataset进行清空或是获取 loader 随机读取的图片路径 #5754

Open Aming1998 opened 2 years ago

Aming1998 commented 2 years ago

PaddleDetection team appreciate any suggestion or problem you delivered~

Checklist:

  1. 查找历史相关issue寻求解答/I have searched related issues but cannot get the expected help.
  2. 翻阅FAQ /I have read the FAQ documentation but cannot get the expected help.

描述问题/Describe the bug

A clear and concise description of what the bug is.

复现/Reproduction

  1. 您使用的命令是? python -u tools/infer_paddle.py -c configs/yolov3_mobilenet_v1_caih_car_220413.yml \ -o weights=output/yolov3_mobilenet_v1_caih_car_220413/best_model\ --infer_dir=dataset/caih_images/img/ \ --output_dir=infer_output/yolov3_mobilenet_v1_caih_car_220413/caih_images \ --save_txt=true \ --save_dir=save_img/ \

2. 您是否更改过代码或配置文件?您是否理解您所更改的内容?还请您提供所更改的部分代码。**提供于后文**

3. 您使用的数据集是?自制数据集

4. 请提供您出现的报错信息及相关log。后文

## 环境/Environment
1. 请提供您使用的Paddle和PaddleDetection的版本号 :Paddle1.6   PaddleDetection0.1

2. 如您在使用PaddleDetection的同时还在使用其他产品,如PaddleServing、PaddleInference等,请您提供其版本号:无

3. 请提供您使用的操作系统信息 :   Linux

4. 请问您使用的Python版本是?

5. 请问您使用的CUDA/cuDNN的版本号是?

目前我们正在使用paddle1.6版本下的paddledetection-0.1的代码进行yolov3网络的检测。目前出现这样一个问题,0.1版的代码提供的infer.py使用的test_feed.dataset存储图片路径,在使用loader读取图片时是随机读取,但是由于项目的一些要求我们需要对图片进行按顺序的读取。

我们对infer.py进行了部分修改以适应自身项目需求

### 1、[将需要按一定的顺序的图片一个一个输入数据集中:此处展示的是输入一张]
croped_img = img[y_start:y_stop, x_start:x_stop, 0:3]
save = FLAGS.save_dir + img_rename + '_' + str(slice_idx) + '.jpg'
cv2.imwrite(save, croped_img)
test_images = []
test_images.append(save)
test_feed.dataset.add_images(test_images)
place = fluid.CUDAPlace(0) if cfg.use_gpu else fluid.CPUPlace()
exe = fluid.Executor(place)

### 2、[此处基本来自infer.py 初始化loader以读取数据]
startup_prog = fluid.Program()
                infer_prog = fluid.Program()
                with fluid.program_guard(infer_prog, startup_prog):
                    with fluid.unique_name.guard():
                        loader, feed_vars = create_feed(test_feed, iterable=False)
                        test_fetches = model.test(feed_vars)

 infer_prog = infer_prog.clone(True)
reader = create_reader(test_feed)
imid2path = reader.imid2path
loader.set_sample_list_generator(reader, place)
exe.run(startup_prog)
if cfg.weights:
        checkpoint.load_params(exe, infer_prog, cfg.weights)

### **3、[问题出在此处:我们在运行代码时发现loader对test_feed.dataset里的图片进行随机读取,同时由于无法对dataset进行清空,所以无法实现按输入顺序预测图片。我们对loader设置为不可迭代式,使得它可以一次性读取一张图片,但这张图片仍然是随机的]**

loader.start()
outs = exe.run(infer_prog,
                        fetch_list=values,
                         return_numpy=False)
res = {
            k: (np.array(v), v.recursive_sequence_lengths())
            for k, v in zip(keys, outs)
          }
 loader.reset()

所以想请问一下test_feed.dataset这个有没有清空这个功能,这样就能实现每次读取的都是刚输入的图片;又或者是否有办法获取loader读取的图片的名称呢?
Aming1998 commented 2 years ago

python 3.7 cuda10、 cudnn 7.6.5

yghstill commented 2 years ago

@Aming1998 可以将image name加入fetch_list中返回即可

Aming1998 commented 2 years ago

@Aming1998 可以将image name加入fetch_list中返回即可

keys, values, _ = parse_fetches(test_fetches, infer_prog, extra_keys)

loader.start() outs = exe.run(infer_prog, fetch_list=values, return_numpy=False) res = { k: (np.array(v), v.recursive_sequence_lengths()) for k, v in zip(keys, outs) }

logger.info('Infer iter {}'.format(iter_id))

loader.reset()根据您刚才的提示 我已经明白了valus应该就是指图片路径的意思?那么这个地方的keys是什么含义呢? 需要修改吗?我感觉它俩是对应的关系

Aming1998 commented 2 years ago

@Aming1998 可以将image name加入fetch_list中返回即可 save = FLAGS.save_dir + imgrename + '' + str(slice_idx) + '.jpg' outs = exe.run(infer_prog, fetch_list=save, return_numpy=False) res = { k: (np.array(v), v.recursive_sequence_lengths()) for k, v in zip(keys, outs) } 我直接将路径输入会出现这样的报错

/usr/local/lib/python2.7/dist-packages/paddle/fluid/executor.py:774: UserWarning: The following exception is not an EOF exception. "The following exception is not an EOF exception.") Traceback (most recent call last): File "tools/infer_paddle_try.py", line 447, in main() File "tools/infer_paddle_try.py", line 372, in main get_test_images(FLAGS) File "tools/infer_paddle_try.py", line 281, in get_test_images return_numpy=False) File "/usr/local/lib/python2.7/dist-packages/paddle/fluid/executor.py", line 775, in run six.reraise(*sys.exc_info()) File "/usr/local/lib/python2.7/dist-packages/paddle/fluid/executor.py", line 770, in run use_program_cache=use_program_cache) File "/usr/local/lib/python2.7/dist-packages/paddle/fluid/executor.py", line 817, in _run_impl use_program_cache=use_program_cache) File "/usr/local/lib/python2.7/dist-packages/paddle/fluid/executor.py", line 894, in _run_program fetch_var_name) paddle.fluid.core_avx.EnforceNotMet:


C++ Call Stacks (More useful to developers):

0 std::string paddle::platform::GetTraceBackString<char const>(char const&&, char const, int) 1 paddle::platform::EnforceNotMet::EnforceNotMet(std::__exception_ptr::exception_ptr, char const, int) 2 paddle::operators::FetchOp::RunImpl(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void> const&) const 3 paddle::framework::OperatorBase::Run(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void> const&) 4 paddle::framework::Executor::RunPreparedContext(paddle::framework::ExecutorPrepareContext, paddle::framework::Scope, bool, bool, bool) 5 paddle::framework::Executor::Run(paddle::framework::ProgramDesc const&, paddle::framework::Scope*, int, bool, bool, std::vector<std::string, std::allocator > const&, bool)


Python Call Stacks (More useful to users):

File "/usr/local/lib/python2.7/dist-packages/paddle/fluid/framework.py", line 2426, in append_op attrs=kwargs.get("attrs", None)) File "/usr/local/lib/python2.7/dist-packages/paddle/fluid/executor.py", line 558, in _add_feed_fetch_ops attrs={'col': i}) File "/usr/local/lib/python2.7/dist-packages/paddle/fluid/executor.py", line 889, in _run_program fetch_var_name=fetch_var_name) File "/usr/local/lib/python2.7/dist-packages/paddle/fluid/executor.py", line 817, in _run_impl use_program_cache=use_program_cache) File "/usr/local/lib/python2.7/dist-packages/paddle/fluid/executor.py", line 770, in run use_program_cache=use_program_cache) File "tools/infer_paddle_try.py", line 281, in get_test_images return_numpy=False) File "tools/infer_paddle_try.py", line 372, in main get_test_images(FLAGS) File "tools/infer_paddle_try.py", line 447, in main()


Error Message Summary:

PaddleCheckError: Cannot find fetch variable in scope, fetch_var_name is save_img/00001_1.jpg at [/paddle/paddle/fluid/operators/controlflow/fetch_op.cc:38] [operator < fetch > error]

yghstill commented 2 years ago

@Aming1998 不是直接的图片路径,因为网络中无法输出图片路径,由于release/0.1的代码太老,你可以更新到0.2的分支吗?在0.2之后就支持了设置shuffle的字段:https://github.com/PaddlePaddle/PaddleDetection/blob/release/0.2/configs/yolov3_reader.yml https://github.com/PaddlePaddle/PaddleDetection/blob/release/0.2/ppdet/data/reader.py#L190

Aming1998 commented 2 years ago

@Aming1998 不是直接的图片路径,因为网络中无法输出图片路径,由于release/0.1的代码太老,你可以更新到0.2的分支吗?在0.2之后就支持了设置shuffle的字段:https://github.com/PaddlePaddle/PaddleDetection/blob/release/0.2/configs/yolov3_reader.yml https://github.com/PaddlePaddle/PaddleDetection/blob/release/0.2/ppdet/data/reader.py#L190

好的 不过能请问一下 是否能够对test_feed.dataset 这个类进行清空操作呢 这样的话 对于我们来说可能会更加地方便一些。