|
|
@@ -30,15 +30,19 @@ class Predictor:
|
|
|
# 输入的大图高度和宽度
|
|
|
self.input_image_h = 0
|
|
|
self.input_image_w = 0
|
|
|
- self.print_network_info()
|
|
|
# 报警的置信度阈值
|
|
|
- self.confidence_threshold = 0.6
|
|
|
+ self.confidence_threshold = 0.85
|
|
|
# 存储连续的帧的检测结果
|
|
|
self.continuous_detection_result = []
|
|
|
# 连续浑浊的patch计数器
|
|
|
self.continuous_counter_mat = np.array(0)
|
|
|
# 判定有浑浊水体时的连续帧数量
|
|
|
- self.max_continuous_frames = 15
|
|
|
+ self.max_continuous_frames = 50
|
|
|
+ # 比例判定的起始帧数
|
|
|
+ self.start_frame_num = self.max_continuous_frames
|
|
|
+ # 比例判定的阈值
|
|
|
+ self.ratio_threshold = 0.85
|
|
|
+ self.print_network_info()
|
|
|
|
|
|
def __call__(self, img) -> bool:
|
|
|
# 预处理,获取输入图像的patch序列和左上角坐标
|
|
|
@@ -76,7 +80,12 @@ class Predictor:
|
|
|
'Height': self.net_h,
|
|
|
'Width': self.net_w,
|
|
|
'Mean': self.mean,
|
|
|
- 'Std': self.std
|
|
|
+ 'Std': self.std,
|
|
|
+ 'Input Image Size': [self.input_image_h, self.input_image_w],
|
|
|
+ 'Confidence Threshold': self.confidence_threshold,
|
|
|
+ 'Max Continuous Frames': self.max_continuous_frames,
|
|
|
+ 'Ratio Threshold': self.ratio_threshold,
|
|
|
+ 'Start Frame Num': self.start_frame_num
|
|
|
}
|
|
|
|
|
|
print("=" * 50)
|
|
|
@@ -154,7 +163,7 @@ class Predictor:
|
|
|
# 第三层 时间滤波
|
|
|
self.continuous_detection_result.append(predicted_class)
|
|
|
flag = self.update_continuous_counter(predicted_class) # 连续帧滤波
|
|
|
- if len(self.continuous_detection_result) >= 20:
|
|
|
+ if len(self.continuous_detection_result) >= self.start_frame_num:
|
|
|
flag = self.discriminate_ratio() and flag
|
|
|
print(f'是否存在浑浊水体,综合判别结果:{flag}')
|
|
|
self.continuous_detection_result.pop(0)
|
|
|
@@ -176,7 +185,7 @@ class Predictor:
|
|
|
positive_index = np.array(pre_class_arr, dtype=np.int32) > 0
|
|
|
negative_index = np.array(pre_class_arr, dtype=np.int32) == 0
|
|
|
# 给负样本区域置零
|
|
|
- self.continuous_counter_mat[negative_index] -= 1
|
|
|
+ self.continuous_counter_mat[negative_index] -= 3
|
|
|
# 给正样本区域加1
|
|
|
self.continuous_counter_mat[positive_index] += 1
|
|
|
# 保证不出现负数
|
|
|
@@ -192,7 +201,7 @@ class Predictor:
|
|
|
# 方式一:60%以上的帧存在浑浊水体
|
|
|
water_pre_arr = np.array(water_pre_list, dtype=np.float32)
|
|
|
water_pre_arr_sum = np.sum(water_pre_arr, axis=0)
|
|
|
- bad_water = np.array(water_pre_arr_sum >= 0.6 * len(water_pre_list), dtype=np.int32)
|
|
|
+ bad_water = np.array(water_pre_arr_sum >= self.ratio_threshold * len(water_pre_list), dtype=np.int32)
|
|
|
bad_flag = bool(np.sum(bad_water, dtype=np.int32) > 2) # 大于两个patch符合要求才可以
|
|
|
# print('比例信息:',water_pre_arr_sum )
|
|
|
print(f'浑浊比例判别:该时间段是否存在浑浊水体:{bad_flag}')
|
|
|
@@ -215,7 +224,7 @@ class Predictor:
|
|
|
return new_predicted_conf_mat.flatten(), new_predicted_class_mat.flatten()
|
|
|
def argsparser():
|
|
|
parser = argparse.ArgumentParser(prog=__file__)
|
|
|
- parser.add_argument('--input','-i', type=str, default=r'4_video_20251223163145', help='path of input, must be image directory')
|
|
|
+ parser.add_argument('--input','-i', type=str, default=r'./4_video_20251223163145', help='path of input, must be image directory')
|
|
|
parser.add_argument('--bmodel','-b', type=str, default='./shufflenet_f32.bmodel', help='path of bmodel')
|
|
|
parser.add_argument('--dev_id','-d', type=int, default=0, help='tpu id')
|
|
|
args = parser.parse_args()
|