-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ICNet for image segmentation. #975
Conversation
fluid/icnet/cityscape.py
Outdated
import numpy as np | ||
import paddle.v2 as paddle | ||
|
||
DATA_PATH = "../../data/cityscape" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
默认路径修改为"./data/cityscape"
fluid/icnet/cityscape.py
Outdated
yield image, label | ||
return reader | ||
|
||
def load(image_label): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
每个方法都要给出简要说明。
fluid/icnet/cityscape.py
Outdated
return image_labels[0].astype("float32"), label_sub1, mask_sub1.astype("int32"), label_sub2, mask_sub2.astype("int32"), label_sub4, mask_sub4.astype("int32") | ||
|
||
|
||
def train(batch_size=32, random_mirror=False, random_scaling=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对外暴露的方法要给出详细使用说明。
fluid/icnet/infer.py
Outdated
_, _, sub124_out = network.icnet(args, images, num_classes, np.array(data_shape[1:]).astype("float32"), is_test=True) | ||
predict = fluid.layers.upsampling_bilinear2d(sub124_out, out_shape=data_shape[1:3]) | ||
predict = fluid.layers.transpose(predict, perm=[0,2,3,1]) | ||
fluid.layers.Print(predict, summarize=10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
去掉Print语句
fluid/icnet/network.py
Outdated
import sys | ||
|
||
|
||
def conv(input, k_h, k_w, c_o, s_h, s_w, relu=True, padding="VALID", group=1, biased=None, name=None, print_pad=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果group
没有被用到,建议将其从参数列表删除。
fluid/icnet/network.py
Outdated
import sys | ||
|
||
|
||
def conv(input, k_h, k_w, c_o, s_h, s_w, relu=True, padding="VALID", group=1, biased=None, name=None, print_pad=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print_op
貌似也是多余的。
fluid/icnet/network.py
Outdated
|
||
def interp(input, out_shape): | ||
out_shape = list(out_shape.astype("int32")) | ||
return fluid.layers.upsampling_bilinear2d(input, out_shape=out_shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最新paddle api已经将upsampling_bilinear2d
重命名为resize_bilinear
fluid/icnet/network.py
Outdated
conv3_3_1_1_increase = conv(conv3_3_3_3_bn, 1, 1, 256, 1, 1, biased=False, relu=False, name="conv3_3_1_1_increase") | ||
conv3_3_1_1_increase_bn = bn(conv3_3_1_1_increase, relu=False, name="conv3_3_1_1_increase_bn", is_test=is_test) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
空行太多。
能否在image-segmentatation 建立一个子目录?便于未来扩展? by guoyi |
@lgone2000 good idea. |
fluid/icnet/README.md
Outdated
|
||
|
||
|
||
本文采用Cityscape数据集,请前往[Cityscape官网]()注册下载。下载数据之后,按照[这里](https://github.com/mcordts/cityscapesScripts)的说明和工具处理数据。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
官网地址补充完整。
fluid/icnet/eval.py
Outdated
place = fluid.CUDAPlace(0) | ||
exe = fluid.Executor(place) | ||
exe.run(fluid.default_startup_program()) | ||
fluid.io.load_persistables(exe, args.model_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对于evaluator来说,只load parameter就行。
fluid/icnet/eval.py
Outdated
exe = fluid.Executor(place) | ||
exe.run(fluid.default_startup_program()) | ||
fluid.io.load_persistables(exe, args.model_path) | ||
print "loaded model from: %s" % args.model_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
判断下model_path是否存在。
fluid/icnet/eval.py
Outdated
fetch_list=fetch_vars) | ||
out_wrong += result[1] | ||
out_right += result[2] | ||
print "count: %s; current iou: %.3f;" % (count, result[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议在同行输出。
fluid/icnet/eval.py
Outdated
add_arg('use_gpu', bool, True, "Whether use GPU to test.") | ||
# yapf: enable | ||
|
||
def cal_mean_iou(wrong, cerroct, num_classes): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cerroct -> correct
fluid/icnet/eval.py
Outdated
|
||
def cal_mean_iou(wrong, cerroct, num_classes): | ||
sum = wrong + cerroct | ||
return (cerroct.astype("float64") / sum).sum() / num_classes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果class i 从来没出现过,那么sum[i]
就是0, 不能直接除;最后求平均也要除真实出现的class数量。
另外num_classes == len(num_classes), 所以可以去掉num_classes这个参数。
fluid/icnet/infer.py
Outdated
add_arg('model_path', str, "", "Model path.") | ||
add_arg('images_list', str, "", "List file with images to be infered.") | ||
add_arg('images_path', str, "", "The images path.") | ||
add_arg('out_path', str, "", "Output path.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
给个默认的out_path. 其它路径也给个默认值。
fluid/icnet/infer.py
Outdated
,[119, 10, 32]] | ||
# 18 = bicycle | ||
|
||
def color(input): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
说明下方法的作用
fluid/icnet/infer.py
Outdated
place = fluid.CUDAPlace(0) | ||
exe = fluid.Executor(place) | ||
exe.run(fluid.default_startup_program()) | ||
fluid.io.load_persistables(exe, args.model_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
load parameter既可
fluid/icnet/infer.py
Outdated
image_t = fluid.core.LoDTensor() | ||
image_t.set(img, place) | ||
result = exe.run(feed={"image": image_t}, fetch_list=[predict]) | ||
cv2.imwrite(args.out_path + "/" + filename + "_result.png", color(result[0])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果args.out_path
不存在,需要新建一个。
fluid/icnet/README.md
Outdated
- https://github.com/hszhao/ICNet | ||
- https://github.com/hellochick/ICNet-tensorflow | ||
- https://github.com/mcordts/cityscapesScripts | ||
- https://zhuanlan.zhihu.com/p/26653218 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参考文献给知乎不够严谨, 只保留一篇paper就行了?
<p align="center"> | ||
<img src="images/train_loss.png" width="620" hspace='10'/> <br/> | ||
<strong>图 2</strong> | ||
</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有mean IoU的结果吗?
fluid/icnet/README.md
Outdated
|
||
## 简介 | ||
|
||
Image Cascade Network(ICNet),在兼顾实时性的同时,比原来的Fast Semantic Segmentation,比如SQ, SegNet, ENet等大大地提高了准确率,足以与Deeplab v2媲美,给语义分割的落地提供了可能。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段中文和后面链接里知乎的中文相同,需要修改。
fluid/icnet/README.md
Outdated
## 简介 | ||
|
||
Image Cascade Network(ICNet),在兼顾实时性的同时,比原来的Fast Semantic Segmentation,比如SQ, SegNet, ENet等大大地提高了准确率,足以与Deeplab v2媲美,给语义分割的落地提供了可能。 | ||
ICNet利用了低分辨率图片的高效处理和高分辨率图片的高推断质量两种优点。主要思想是:让低分辨率图像经过整个语义网络输出一个粗糙的预测,然后利用文中提出的级联融合单元来引入中分辨率和高分辨率图像的特征,从而逐渐提高精度。整个网络结构如下: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上,和知乎的中文描述相同,需要修改。
fluid/icnet/README.md
Outdated
|
||
|
||
|
||
本文采用Cityscape数据集,请前往[Cityscape官网]()注册下载。下载数据之后,按照[这里](https://github.com/mcordts/cityscapesScripts)的说明和工具处理数据。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
进入https://github.com/mcordts/cityscapesScripts 这个链接里,一眼看去,看不懂如何处理数据,我们这里可以提供处理脚本吗?
fluid/icnet/cityscape.py
Outdated
def test(): | ||
reader = DataGenerater(TEST_LIST).create_reader() | ||
reader = paddle.reader.map_readers(load, reader) | ||
reader = paddle.reader.map_readers(test_process, reader) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要两个 paddle.reader.map_readers
吧。
fluid/icnet/infer.py
Outdated
# define network | ||
images = fluid.layers.data(name='image', shape=data_shape, dtype='float32') | ||
_, _, sub124_out = network.icnet(args, images, num_classes, np.array(data_shape[1:]).astype("float32"), is_test=True) | ||
predict = fluid.layers.upsampling_bilinear2d(sub124_out, out_shape=data_shape[1:3]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upsampling_bilinear2d -> resize_bilinear
fluid/icnet/infer.py
Outdated
fluid.io.load_persistables(exe, args.model_path) | ||
print "loaded model from: %s" % args.model_path | ||
sys.stdout.flush() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
因为网络中有BN,需要:
inference_program = fluid.default_main_program().clone(for_test=True)
下面83行的exe运行这个 inference_program
fluid/icnet/network.py
Outdated
|
||
sub4_out = conv(conv5_4_interp, 1, 1, num_classes, 1, 1, biased=True, relu=False, name="sub4_out") | ||
|
||
sub24_out = conv(sub24_sum_interp, 1, 1, num_classes, 1, 1, biased=True, relu=False, name="sub24_out") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
上面网络可以模块化的写下吗? 现在看着网络特别复杂。
fluid/icnet/network.py
Outdated
@@ -0,0 +1,337 @@ | |||
import paddle.fluid as fluid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
network.py 有更精确的名字吗?
已按review修改代码。请@wanghaoshuang @qingqing01 确认。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 不知道 @qingqing01 还有什么意见么?
No description provided.