未验证 提交 0856a58c 编写于 作者: G guochaorong 提交者: GitHub

Merge pull request #1141 from wanghaoshuang/fix_icnet_v2

Use paddle.dataset.image instead of paddle.v2.image in icnet
......@@ -3,7 +3,7 @@
import os
import cv2
import numpy as np
import paddle.v2 as paddle
import paddle.dataset as dataset
DATA_PATH = "./data/cityscape"
TRAIN_LIST = DATA_PATH + "/train.list"
......@@ -83,7 +83,7 @@ class DataGenerater:
def reader():
for image, label in self.image_label:
image, label = self.load(image, label)
image = paddle.image.to_chw(image)[np.newaxis, :]
image = dataset.image.to_chw(image)[np.newaxis, :]
label = label[np.newaxis, :, :, np.newaxis].astype("float32")
label_mask = np.where((label != IGNORE_LABEL).flatten())[
0].astype("int32")
......@@ -102,20 +102,20 @@ class DataGenerater:
image, label = self.random_scaling(image, label)
image, label = self.resize(image, label, out_size=TRAIN_DATA_SHAPE[1:])
label = label.astype("float32")
label_sub1 = paddle.image.to_chw(self.scale_label(label, factor=4))
label_sub2 = paddle.image.to_chw(self.scale_label(label, factor=8))
label_sub4 = paddle.image.to_chw(self.scale_label(label, factor=16))
image = paddle.image.to_chw(image)
label_sub1 = dataset.image.to_chw(self.scale_label(label, factor=4))
label_sub2 = dataset.image.to_chw(self.scale_label(label, factor=8))
label_sub4 = dataset.image.to_chw(self.scale_label(label, factor=16))
image = dataset.image.to_chw(image)
return image, label_sub1, label_sub2, label_sub4
def load(self, image, label):
"""
Load image from file.
"""
image = paddle.image.load_image(
image = dataset.image.load_image(
DATA_PATH + "/" + image, is_color=True).astype("float32")
image -= IMG_MEAN
label = paddle.image.load_image(
label = dataset.image.load_image(
DATA_PATH + "/" + label, is_color=False).astype("float32")
return image, label
......@@ -125,8 +125,8 @@ class DataGenerater:
"""
r = np.random.rand(1)
if r > 0.5:
image = paddle.image.left_right_flip(image, is_color=True)
label = paddle.image.left_right_flip(label, is_color=False)
image = dataset.image.left_right_flip(image, is_color=True)
label = dataset.image.left_right_flip(label, is_color=False)
return image, label
def random_scaling(self, image, label):
......@@ -163,7 +163,7 @@ class DataGenerater:
combined = np.concatenate((image, label), axis=2)
combined = self.padding_as(
combined, out_size[0], out_size[1], is_color=True)
combined = paddle.image.random_crop(
combined = dataset.image.random_crop(
combined, out_size[0], is_color=True)
image = combined[:, :, 0:3]
label = combined[:, :, 3:4] + ignore_label
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册