Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

[WIP] Debug lm bisenet #567

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions dlk/examples/segmentation/lm_bisenet_quantize_camvid/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
BATCH_SIZE: 1
CLASSES:
- sky
- building
- pole
- road
- pavement
- tree
- signsymbol
- fence
- car
- pedestrian
- bicyclist
DATASET:
AUGMENTOR: !!python/object:lmnet.data_processor.Sequence
processors:
- !!python/object:lmnet.pre_processor.Resize
size:
- 352
- 480
- !!python/object:lmnet.data_augmentor.Brightness
max_value: 1.25
min_value: 0.75
- !!python/object:lmnet.data_augmentor.Color
max_value: 1.25
min_value: 0.75
- !!python/object:lmnet.data_augmentor.Contrast
max_value: 1.25
min_value: 0.75
- !!python/object:lmnet.data_augmentor.FlipLeftRight
probability: 0.5
- !!python/object:lmnet.data_augmentor.Hue
max_value: 10
min_value: -10
BATCH_SIZE: 1
DATA_FORMAT: NHWC
ENABLE_PREFETCH: true
PRE_PROCESSOR: !!python/object:lmnet.data_processor.Sequence
processors:
- !!python/object:lmnet.pre_processor.Resize
size:
- 352
- 480
- !!python/object:lmnet.pre_processor.PerImageStandardization {}
DATASET_CLASS: !!python/name:lmnet.datasets.camvid.Camvid ''
DATA_FORMAT: NHWC
IMAGE_SIZE:
- 352
- 480
IS_DEBUG: false
IS_PRETRAIN: false
KEEP_CHECKPOINT_MAX: 5
MAX_EPOCHS: 1
NETWORK:
ACTIVATION_QUANTIZER: !!python/name:lmnet.quantizations.linear.linear_mid_tread_half_quantizer ''
ACTIVATION_QUANTIZER_KWARGS:
bit: 2
max_value: 2
AUXILIARY_LOSS_WEIGHT: 0.5
BATCH_SIZE: 1
DATA_FORMAT: NHWC
IMAGE_SIZE:
- 352
- 480
OPTIMIZER_CLASS: !!python/name:tensorflow.python.training.adam.AdamOptimizer ''
OPTIMIZER_KWARGS:
learning_rate: 0.001
USE_ATTENTION_REFINEMENT: false
USE_FEATURE_FUSION: false
USE_TAIL_GAP: false
WEIGHT_DECAY_RATE: 0.0
WEIGHT_QUANTIZER: !!python/name:lmnet.quantizations.binary.binary_channel_wise_mean_scaling_quantizer ''
WEIGHT_QUANTIZER_KWARGS: {}
NETWORK_CLASS: !!python/name:lmnet.networks.segmentation.lm_bisenet.LMBiSeNetQuantize ''
POST_PROCESSOR: !!python/object:lmnet.data_processor.Sequence
processors:
- !!python/object:lmnet.post_processor.Bilinear
compatible_tensorflow_v1: true
data_format: NHWC
size:
- 352
- 480
- !!python/object:lmnet.post_processor.Softmax {}
PRETRAIN_DIR: ''
PRETRAIN_FILE: ''
PRETRAIN_VARS: []
PRE_PROCESSOR: !!python/object:lmnet.data_processor.Sequence
processors:
- !!python/object:lmnet.pre_processor.Resize
size:
- 352
- 480
- !!python/object:lmnet.pre_processor.PerImageStandardization {}
SAVE_CHECKPOINT_STEPS: 1000
SUMMARISE_STEPS: 1000
TASK: !!python/object/apply:lmnet.common.Tasks
- IMAGE.SEMANTIC_SEGMENTATION
TEST_STEPS: 1000
Binary file not shown.
31 changes: 31 additions & 0 deletions dlk/examples/segmentation/lm_bisenet_quantize_camvid/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
CLASSES:
- sky
- building
- pole
- road
- pavement
- tree
- signsymbol
- fence
- car
- pedestrian
- bicyclist
DATA_FORMAT: NHWC
IMAGE_SIZE:
- 352
- 480
POST_PROCESSOR:
- Bilinear:
compatible_tensorflow_v1: true
data_format: NHWC
size:
- 352
- 480
- Softmax: null
PRE_PROCESSOR:
- Resize:
size:
- 352
- 480
- PerImageStandardization: null
TASK: IMAGE.SEMANTIC_SEGMENTATION
Binary file not shown.
15 changes: 15 additions & 0 deletions dlk/tests/test_code_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ def dict_codegen_segmentation(cpu_name) -> dict:
}


def dict_codegen_lm_bisenet(cpu_name) -> dict:
"""Test parameters for testing code generation for segmentation on CPU"""
return {'model_path': os.path.join('examples', 'segmentation', 'lm_bisenet_quantize_camvid'),
'expected_output_set_name': 'inference_test_data',
'prefix': 'lm_bisenet',
'input_name': '000_images_placeholder:0.npy',
'output_npy_name': '655_output:0.npy',
'cpu_name': cpu_name,
'hard_quantize': True,
'threshold_skipping': False,
'use_avx': False
}


def get_configurations_by_test_cases(test_cases, configuration):

return [updated_dict(configuration,test_case) for test_case in test_cases]
Expand All @@ -101,6 +115,7 @@ def get_configurations_by_architecture(test_cases, cpu_name):
configurations.extend(get_configurations_by_test_cases(test_cases, dict_codegen_classification_resnet(cpu_name)))
configurations.extend(get_configurations_by_test_cases(test_cases, dict_codegen_object_detection(cpu_name)))
configurations.extend(get_configurations_by_test_cases(test_cases, dict_codegen_segmentation(cpu_name)))
configurations.extend(get_configurations_by_test_cases(test_cases, dict_codegen_lm_bisenet(cpu_name)))

return configurations

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
ulimits:
memlock: -1
stack: 67108864
network_mode: "host"
working_dir: /home/blueoil
volumes:
- ./:/home/blueoil
Expand Down
113 changes: 113 additions & 0 deletions lmnet/configs/lm_bisenet_quantize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# -*- coding: utf-8 -*-
# Copyright 2019 The Blueoil Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# =============================================================================
from easydict import EasyDict
import tensorflow as tf

from lmnet.common import Tasks
from lmnet.networks.segmentation.lm_bisenet import LMBiSeNetQuantize
from lmnet.datasets.camvid import Camvid
from lmnet.data_processor import Sequence
from lmnet.pre_processor import (
Resize,
PerImageStandardization,
)
from lmnet.post_processor import (
Bilinear,
Softmax,
)
from lmnet.data_augmentor import (
Brightness,
Color,
Contrast,
FlipLeftRight,
Hue,
)
from lmnet.quantizations import (
binary_channel_wise_mean_scaling_quantizer,
linear_mid_tread_half_quantizer,
)

IS_DEBUG = False

NETWORK_CLASS = LMBiSeNetQuantize
DATASET_CLASS = Camvid

IMAGE_SIZE = [352, 480]
BATCH_SIZE = 8
DATA_FORMAT = "NHWC"
TASK = Tasks.SEMANTIC_SEGMENTATION
CLASSES = DATASET_CLASS.classes

MAX_EPOCHS = 1
SAVE_CHECKPOINT_STEPS = 1000
KEEP_CHECKPOINT_MAX = 5
TEST_STEPS = 1000
SUMMARISE_STEPS = 1000


# pretrain
IS_PRETRAIN = False
PRETRAIN_VARS = []
PRETRAIN_DIR = ""
PRETRAIN_FILE = ""

# for debug
# BATCH_SIZE = 2
# SUMMARISE_STEPS = 1
# IS_DEBUG = True

PRE_PROCESSOR = Sequence([
Resize(size=IMAGE_SIZE),
PerImageStandardization(),
])
POST_PROCESSOR = Sequence([
Bilinear(size=IMAGE_SIZE, data_format=DATA_FORMAT, compatible_tensorflow_v1=True),
Softmax(),
])


NETWORK = EasyDict()
NETWORK.OPTIMIZER_CLASS = tf.train.AdamOptimizer
NETWORK.OPTIMIZER_KWARGS = {"learning_rate": 0.001}
NETWORK.IMAGE_SIZE = IMAGE_SIZE
NETWORK.BATCH_SIZE = BATCH_SIZE
NETWORK.DATA_FORMAT = DATA_FORMAT
NETWORK.WEIGHT_DECAY_RATE = 0.
NETWORK.AUXILIARY_LOSS_WEIGHT = 0.5
NETWORK.USE_FEATURE_FUSION = False
NETWORK.USE_ATTENTION_REFINEMENT = False
NETWORK.USE_TAIL_GAP = False
NETWORK.ACTIVATION_QUANTIZER = linear_mid_tread_half_quantizer
NETWORK.ACTIVATION_QUANTIZER_KWARGS = {
'bit': 2,
'max_value': 2
}
NETWORK.WEIGHT_QUANTIZER = binary_channel_wise_mean_scaling_quantizer
NETWORK.WEIGHT_QUANTIZER_KWARGS = {}

DATASET = EasyDict()
DATASET.BATCH_SIZE = BATCH_SIZE
DATASET.DATA_FORMAT = DATA_FORMAT
DATASET.PRE_PROCESSOR = PRE_PROCESSOR
DATASET.AUGMENTOR = Sequence([
Resize(size=IMAGE_SIZE),
Brightness((0.75, 1.25)),
Color((0.75, 1.25)),
Contrast((0.75, 1.25)),
FlipLeftRight(),
Hue((-10, 10)),
])
DATASET.ENABLE_PREFETCH = True
2 changes: 1 addition & 1 deletion lmnet/lmnet/networks/segmentation/lm_bisenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def _context(self, x):
with tf.variable_scope("block_3"):
x = self._space_to_depth(name='s2d_3', inputs=x)
x = self._block('conv_1', x, 512, 1)
growth_rate = 256
growth_rate = 128
bottleneck_rate = 1
x = densenet_group(
"dense",
Expand Down