下のコードを実行すると、以下のエラー分と出力結果が出てきます。
1.0と出力されている部分がおかしいです。
ちゃんと読み込めてはいると思うのですが。。。
DeprecationWarning: elementwise comparison failed; this will raise an error in the future. target_diff = np.count_nonzero(result_img != target_img) 00257_00264_00.png out00_01.png 0 0 ・ ・ ・ 1.0 #マスク画像と比較 434 #隣と比較
python
1import pathlib 2import argparse 3import sys 4 5################################################################ 6def get_filenames_of_path(path: pathlib.Path, ext: str = "*"): 7 """Returns a list of files in a directory/path. Uses pathlib.""" 8 filenames = [file for file in path.glob(ext) if file.is_file()] 9 filenames.sort() 10 return filenames 11 12################################################################ 13def get_args(): 14 parser = argparse.ArgumentParser(description='Evaluate result', 15 formatter_class=argparse.ArgumentDefaultsHelpFormatter) 16 parser.add_argument('target_dir', type=str) 17 parser.add_argument('result_dir', type=str) 18 19 return parser.parse_args() 20 21################################################################ 22args = get_args() 23 24result_dir = pathlib.Path.cwd() / args.result_dir 25target_dir = pathlib.Path.cwd() / args.target_dir 26 27################################################################ 28import numpy as np 29import torch 30from skimage.io import imread, imsave 31 32# input and target files 33result_names = get_filenames_of_path(result_dir) 34target_names = get_filenames_of_path(target_dir) 35 36# read images and store them in memory 37result_imgs = [imread(str(result_name)) for result_name in result_names] 38target_imgs = [imread(str(target_name)) for target_name in target_names] 39 40if len(result_imgs) == 0 or len(target_imgs) == 0: 41 print("result or target is empty!!") 42 sys.exit() 43 44img_num = min(len(target_imgs), len(result_imgs)) 45 46target_sum = 0 47target_diff = 0 48 49prev_sum = 0 50prev_diff = 0 51prev_img = None 52for i in range(img_num): 53 result_img = result_imgs[i] & 1 54 # target_img = target_imgs[i] * 255 55 target_img = target_imgs[i] & 1 56 57 # print(result_img.shape) 58 # print(target_img.shape) 59 60 target_diff = np.count_nonzero(result_img != target_img) 61 if i > 0: 62 prev_diff = np.count_nonzero(result_img != prev_img) 63 64 print(f"{result_names[i].name} {target_names[i].name} {target_diff} {prev_diff}") 65 target_sum += target_diff 66 prev_sum += prev_diff 67 68 prev_img = result_img 69 70print(target_sum/img_num) 71print(prev_sum/(img_num-1))
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/01/19 02:57 編集
2022/01/19 04:13
2022/01/19 04:45
2022/01/19 05:44