(outputs, output_dir, model_name)
| 24 | return img |
| 25 | |
| 26 | def postprocess(outputs, output_dir, model_name): |
| 27 | # 反归一化 |
| 28 | img = (outputs[0] * 0.5 + 0.5) * 255. |
| 29 | |
| 30 | # 限幅 |
| 31 | img = np.clip(img, 0, 255).astype(np.uint8) |
| 32 | |
| 33 | # 转置 |
| 34 | img = img.transpose((1, 2, 0)) |
| 35 | |
| 36 | # 检查输出目录 |
| 37 | if not os.path.exists(output_dir): |
| 38 | os.makedirs(output_dir) |
| 39 | |
| 40 | # 写入输出图片 |
| 41 | cv2.imwrite(os.path.join(output_dir, '%s.jpg' % model_name), img) |