
分类任务是人工智能中最常见的任务,因为它需要很少的库。我尝试使用在线编译器的资源进行编写,但不了解工作的复杂性。
def rle_decode(mask_rle, shape=(1280, 1918, 1)):
'''
mask_rle: run-length as string formated (start length)
shape: (height,width) of array to return
returns numpy array, 1 - mask, 0 - background
'''
img = np.zeros(shape[0]*shape[1], dtype=np.uint8)
s = mask_rle.split()
starts, lengths = [np.asarray(x, dtype=int) for x in (s[0:][::2], s[1:][::2])]
starts -= 1
ends = starts + lengths
for lo, hi in zip(starts, ends):
img[lo:hi] = 1
img = img.reshape(shape)
return img
例如,使用解码掩码0/1的功能,您可以依赖它们的长度。但要生成神经网络的批量数据包,您仍然需要监控当前结果。
def keras_generator(gen_df, batch_size):
while true:
x_batch = []
y_batch = []
for i in range(batch_size):
img_name, mask_rle = gen_df.sample(1).values[0]
img = cv2.imread('data/train/{}'.format(img_name))
mask = rle_decode(mask_rle)
img = cv2.resize(img, (256, 256))
mask = cv2.resize(mask, (256, 256))
x_batch += [img]
y_batch += [mask]
x_batch = np.array(x_batch) / 255.
y_batch = np.array(y_batch)
yield x_batch, np.expand_dims(y_batch, -1)
im_id = 5 fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(25, 25)) axes[0].imshow(x[im_id]) axes[1].imshow(pred[im_id, ..., 0] > 0.5) plt.show()
结果的输出=保证与编写的代码接触。在这种情况下,不需要异常处理。
以上就是高效的错误处理程序的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号