milesial / Pytorch-UNet

PyTorch implementation of the U-Net for image semantic segmentation with high quality images
GNU General Public License v3.0
9.05k stars 2.47k forks source link

Questions about 'predict.py'' #433

Open ZhaoQs999 opened 1 year ago

ZhaoQs999 commented 1 year ago

If I want to predict the pictures of a folder, how can I modify the code and run the code? I typed the following in the terminal and got that the test folder could not be found. 如果我想预测一个文件夹的图片,我该怎么修改代码和运行代码呢?我在终端输入如下,得到的是找不到该测试文件夹。 image

ZhaoQs999 commented 1 year ago

My test image is placed in Pytorch-UNet-master/result/test/.

milesial commented 1 year ago

-i and -o expect input and output individual images, not folders. You could just call this script in a bash or python loop over all your images.

Andy-0105 commented 6 months ago

Modify predict.py to read the image part

for i, filename in enumerate(in_files):
    logging.info(f'Predicting image {filename} ...')
    image_files = [f for f in os.listdir(filename) if f.endswith('.jpg') or f.endswith('.png')]
    for file in image_files:
        input_image_path = os.path.join(filename, file)
        img = Image.open(input_image_path)
        start_image_time = time.time()
        mask = predict_img(net=net,
                           full_img=img,
                           scale_factor=args.scale,
                           out_threshold=args.mask_threshold,
                           device=device)