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

Mrcnn #733

Draft
wants to merge 57 commits into
base: master
Choose a base branch
from
Draft

Mrcnn #733

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
ca3522a
update the path in README
LucienZhang Nov 7, 2019
ff1c212
Merge remote-tracking branch 'upstream/master'
LucienZhang Nov 11, 2019
00eb749
the size of input image should be 32x32, see https://www.cs.toronto.e…
LucienZhang Nov 11, 2019
b0b88da
the explanation about max_to_keep=0 does not make sense, and see http…
LucienZhang Nov 11, 2019
0e18423
replace old config in example with the latest one.
LucienZhang Nov 12, 2019
e26604d
do not merge to master
LucienZhang Nov 13, 2019
a08be1f
Merge remote-tracking branch 'upstream/master'
LucienZhang Nov 19, 2019
5c0e868
Merge branch 'master' into mrcnn
LucienZhang Nov 19, 2019
d170f14
resnet-imagenet for mask rcnn
LucienZhang Nov 19, 2019
bdf7a41
change config
LucienZhang Nov 20, 2019
d764f85
backbone
LucienZhang Nov 22, 2019
3c77a9d
backbone
LucienZhang Nov 22, 2019
1da3815
backbone
LucienZhang Nov 22, 2019
dc2e4ca
backbone
LucienZhang Nov 22, 2019
4de22a0
config
LucienZhang Nov 22, 2019
26f89d1
modify
LucienZhang Nov 22, 2019
7a5d9bf
Merge branch 'master' of github.com:blue-oil/blueoil into mrcnn
LucienZhang Dec 4, 2019
099dbe3
original model+resnet18+weight_quantizer
LucienZhang Dec 6, 2019
33c4b23
test activation
LucienZhang Dec 10, 2019
0de0f90
path
LucienZhang Dec 10, 2019
859b5b4
path
LucienZhang Dec 10, 2019
da50a27
what im training for backbone
LucienZhang Dec 20, 2019
3e71fd7
add val gen in backbone
LucienZhang Dec 20, 2019
f64ce86
train strategy and linking file
LucienZhang Dec 20, 2019
ae53c2b
weights name
LucienZhang Dec 20, 2019
43f34e7
parameter
LucienZhang Dec 20, 2019
cdd46e6
resnet18 return value unpack
LucienZhang Dec 20, 2019
eea6a0a
lambda to activation
LucienZhang Dec 23, 2019
fc6075e
test
LucienZhang Dec 23, 2019
b5516fe
try K.tf
LucienZhang Dec 23, 2019
5bf5e9a
use closure in linear
LucienZhang Dec 23, 2019
c90160f
try outer save
LucienZhang Dec 23, 2019
1d91e92
try to use freeze session
LucienZhang Dec 23, 2019
8c7fd24
add checkpoint
LucienZhang Dec 24, 2019
256ed93
checkpoint
LucienZhang Dec 24, 2019
6d45999
no val
LucienZhang Dec 24, 2019
caa569c
multi gpu
LucienZhang Dec 24, 2019
cde22e6
multi gpu
LucienZhang Dec 24, 2019
751336b
test
LucienZhang Dec 24, 2019
0a76639
back to just checkpoint
LucienZhang Dec 24, 2019
09e2faa
checkpoint
LucienZhang Dec 24, 2019
dc2ed57
backbone path
LucienZhang Jan 6, 2020
7efe67c
add visualize for camera
LucienZhang Jan 6, 2020
8bd1c32
weights quantizer
LucienZhang Jan 6, 2020
a599105
padding upper
LucienZhang Jan 6, 2020
b672d1b
compute shape
LucienZhang Jan 6, 2020
23a4a7d
padding lower
LucienZhang Jan 6, 2020
f2f65e5
single gpu
LucienZhang Jan 6, 2020
129dd99
config
LucienZhang Jan 7, 2020
175f568
save balloon model
LucienZhang Jan 7, 2020
f83d67d
save balloon model
LucienZhang Jan 7, 2020
81bff47
smaller backbone
LucienZhang Jan 7, 2020
544057e
fully quantized, except for mrcnn class
LucienZhang Jan 9, 2020
c3f1b4d
import
LucienZhang Jan 9, 2020
3ad3f43
fcn most quantized, works
LucienZhang Jan 10, 2020
e7d64de
fcn can not be quantized too much
LucienZhang Jan 14, 2020
e1aff03
only quantize backbone coco
LucienZhang Jan 14, 2020
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
2 changes: 2 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
[submodule "lmnet/third_party/coco"]
path = lmnet/third_party/coco
url = https://github.com/pdollar/coco.git
ignore = dirty
[submodule "lmnet/third_party/tensorflow-on-arm"]
path = lmnet/third_party/tensorflow-on-arm
url = https://github.com/lhelontra/tensorflow-on-arm.git

9 changes: 9 additions & 0 deletions dlk/argmax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sys
import numpy as np
array=[]
for line in sys.stdin:
if 'Output' in line or 'test' in line:
continue
array.extend([float(n) for n in line.strip('[] \r\n').split()])
print(array)
print(np.argmax(array))
5 changes: 5 additions & 0 deletions lmnet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dataset/
images/
log
outputs/
saved/
6 changes: 3 additions & 3 deletions lmnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ Currently, this feature is implemented for quantized classification of cifar10 a
If you don't want to use this feature, set TRAIN_VALIDATION_SAVING_SIZE to zero.

The KEEP_CHECKPOINT_MAX is equivalent to 'max_to_keep' of tensorflow train.Saver parameter which indicates the maximum number of recent checkpoint files to keep. As new files are created, older files are deleted.
If None or 0, no checkpoints are deleted from the filesystem but only the last one is kept in the checkpoint file. Defaults to 5 (that is, the 5 most recent checkpoint files are kept.)
If None or 0, no checkpoints but only the last one is kept in the checkpoint file. Defaults to 5 (that is, the 5 most recent checkpoint files are kept.)

To apply this feature to another dataset, the dataset file should define another available subset called train_validation_saving, which is split from the original train dataset in the dataset file. Also a dataset parameter TRAIN_VALIDATION_SAVING_SIZE should be included in the config file.

Expand All @@ -225,7 +225,7 @@ Exporting a trained model to proto buffer files and meta config yaml.
In the case with `images` option, create each layer output value npy files in `export/{restore_path}/{image_size}/{image_name}/**.npy` for debug.

* Load config file from saved experiment dir.
* Export config file to yaml. See also [Config specification](docs/specification/config.md).
* Export config file to yaml. See also [Config specification](../docs/specification/config.md).
* `config.yaml` can be used for training and evaluation in python. i.e. [classification.yaml](configs/example/classification.yaml) is exported from [classification.py](configs/example/classification.py)
* `meta.yaml` include only few parameter for application such as demo. i.e. [classification_meta.yaml](configs/example/classification_meta.yaml) is exported from [classification.py](configs/example/classification.py)
* Save the model protocol buffer files (tf) for DLK converter.
Expand Down Expand Up @@ -328,7 +328,7 @@ Save the predictions npy, json, images results to output dir.
* json: `{output_dir}/json/{batch number}.json`
* images: `{output_dir}/images/{some type}/{input image file name}`

The output predictions Tensor(npy) and json format depends on task type. Plsease see [Output Data Specification](docs/specification/output_data.md).
The output predictions Tensor(npy) and json format depends on task type. Plsease see [Output Data Specification](../docs/specification/output_data.md).

```
python3 executor/predict.py -h
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# -*- 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

from lmnet.common import Tasks
from lmnet.networks.instance_segmentation_old.resnet18_backbone import ResnetQuantize
#from lmnet.networks.classification.lm_resnet import LmResnetQuantize
from lmnet.datasets.ilsvrc_2012 import Ilsvrc2012
from lmnet.data_processor import Sequence
from lmnet.pre_processor import (
Resize,
DivideBy255,
)
from lmnet.data_augmentor import (
Brightness,
Color,
Contrast,
Crop,
FlipLeftRight,
Hue,
)

from lmnet.quantizations import (
binary_mean_scaling_quantizer,
linear_mid_tread_half_quantizer,
)

IS_DEBUG = False

NETWORK_CLASS = ResnetQuantize
DATASET_CLASS = Ilsvrc2012

IMAGE_SIZE = [224, 224]
BATCH_SIZE = 4
DATA_FORMAT = "NHWC"
TASK = Tasks.CLASSIFICATION
CLASSES = DATASET_CLASS.classes

# MAX_STEPS = 2000000
# SAVE_CHECKPOINT_STEPS = 50000
# KEEP_CHECKPOINT_MAX = 5
# TEST_STEPS = 50000
# SUMMARISE_STEPS = 50000
# USE_RECOVERY = True
# pretrain
IS_PRETRAIN = False
PRETRAIN_VARS = []
PRETRAIN_DIR = ""
PRETRAIN_FILE = ""


# for debug
MAX_STEPS = 100
# BATCH_SIZE = 31
SAVE_CHECKPOINT_STEPS = 10
KEEP_CHECKPOINT_MAX = 5
TEST_STEPS = 10
SUMMARISE_STEPS = 2
# IS_DEBUG = True

PRE_PROCESSOR = Sequence([
Resize(size=IMAGE_SIZE),
DivideBy255()
])
POST_PROCESSOR = None

NETWORK = EasyDict()
# NETWORK.OPTIMIZER_CLASS = tf.train.MomentumOptimizer
# NETWORK.OPTIMIZER_KWARGS = {"momentum": 0.9}
# NETWORK.LEARNING_RATE_FUNC = tf.train.piecewise_constant
# NETWORK.LEARNING_RATE_KWARGS = {
# "values": [0.1, 0.01, 0.001, 0.0001],
# "boundaries": [40000, 60000, 80000],
# }
NETWORK.IMAGE_SIZE = IMAGE_SIZE
NETWORK.BATCH_SIZE = BATCH_SIZE
NETWORK.DATA_FORMAT = DATA_FORMAT
# NETWORK.WEIGHT_DECAY_RATE = 0.0001
NETWORK.ACTIVATION_QUANTIZER = linear_mid_tread_half_quantizer
NETWORK.ACTIVATION_QUANTIZER_KWARGS = {
'bit': 2,
'max_value': 2
}
NETWORK.WEIGHT_QUANTIZER = binary_mean_scaling_quantizer
NETWORK.WEIGHT_QUANTIZER_KWARGS = {}

# dataset
DATASET = EasyDict()
DATASET.BATCH_SIZE = BATCH_SIZE
DATASET.DATA_FORMAT = DATA_FORMAT
DATASET.PRE_PROCESSOR = PRE_PROCESSOR
DATASET.AUGMENTOR = Sequence([
# Pad(2),
Crop(size=IMAGE_SIZE),
# FlipLeftRight(),
# Crop(size=IMAGE_SIZE, resize=256),
FlipLeftRight(),
# Brightness((0.75, 1.25)),
# Color((0.75, 1.25)),
# Contrast((0.75, 1.25)),
# Hue((-10, 10)),
])
DATASET.ENABLE_PREFETCH = True
77 changes: 37 additions & 40 deletions lmnet/configs/example/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,77 @@
#
# 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.
# WITH 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.classification.lmnet_v1 import LmnetV1Quantize
from lmnet.datasets.cifar10 import Cifar10
from lmnet.networks.classification.lmnet_v0 import LmnetV0Quantize
from lmnet.data_processor import Sequence
from lmnet.pre_processor import (
Resize,
PerImageStandardization,
DivideBy255,
)
from lmnet.data_augmentor import (
Brightness,
Color,
Contrast,
Crop,
FlipLeftRight,
Hue,
Pad,
)
from lmnet.quantizations import (
binary_mean_scaling_quantizer,
linear_mid_tread_half_quantizer,
)

IS_DEBUG = True
IS_DEBUG = False

NETWORK_CLASS = LmnetV0Quantize
NETWORK_CLASS = LmnetV1Quantize
DATASET_CLASS = Cifar10

IMAGE_SIZE = [28, 28]
BATCH_SIZE = 32
IMAGE_SIZE = [32, 32]
BATCH_SIZE = 100
DATA_FORMAT = "NHWC"
TASK = Tasks.CLASSIFICATION
CLASSES = DATASET_CLASS.classes

MAX_STEPS = 100000
SAVE_CHECKPOINT_STEPS = 1000
KEEP_CHECKPOINT_MAX = 5
MAX_EPOCHS = 1 # MAX_STEPS = 1561
SAVE_CHECKPOINT_STEPS = 100
TEST_STEPS = 100
SUMMARISE_STEPS = 10


TEST_STEPS = 1000
SUMMARISE_STEPS = 100
# pretrain
IS_PRETRAIN = False
PRETRAIN_VARS = [
"conv1/kernel:",
"conv1/bias:",
"conv2/kernel:",
"conv2/bias:",
"conv3/kernel:",
"conv3/bias:",
"conv4/kernel:",
"conv4/bias:",
"conv5/kernel:",
"conv5/bias:",
"conv6/kernel:",
"conv6/bias:",
]
PRETRAIN_DIR = "saved/lmnet_0.01_caltech101/checkpoints"
PRETRAIN_FILE = "save.ckpt-99001"
PRETRAIN_VARS = []
PRETRAIN_DIR = ""
PRETRAIN_FILE = ""


# for debug
# MAX_STEPS = 10
# BATCH_SIZE = 31
# SAVE_CHECKPOINT_STEPS = 2
# TEST_STEPS = 10
# SUMMARISE_STEPS = 2
# IS_DEBUG = True

PRE_PROCESSOR = Sequence([
Resize(size=IMAGE_SIZE),
PerImageStandardization()
DivideBy255()
])
POST_PROCESSOR = None

NETWORK = EasyDict()
NETWORK.OPTIMIZER_CLASS = tf.train.AdamOptimizer
NETWORK.OPTIMIZER_KWARGS = {"learning_rate": 0.001}
NETWORK.OPTIMIZER_CLASS = tf.train.MomentumOptimizer
NETWORK.OPTIMIZER_KWARGS = {"momentum": 0.9}
NETWORK.LEARNING_RATE_FUNC = tf.train.piecewise_constant
step_per_epoch = int(50000 / BATCH_SIZE)
NETWORK.LEARNING_RATE_KWARGS = {
"values": [0.01, 0.001, 0.0001, 0.00001],
"boundaries": [step_per_epoch * 50, step_per_epoch * 100, step_per_epoch * 150],
}
NETWORK.IMAGE_SIZE = IMAGE_SIZE
NETWORK.BATCH_SIZE = BATCH_SIZE
NETWORK.DATA_FORMAT = DATA_FORMAT
Expand All @@ -100,9 +98,8 @@
DATASET.DATA_FORMAT = DATA_FORMAT
DATASET.PRE_PROCESSOR = PRE_PROCESSOR
DATASET.AUGMENTOR = Sequence([
Pad(2),
Crop(size=IMAGE_SIZE),
FlipLeftRight(),
Brightness((0.75, 1.25)),
Color((0.75, 1.25)),
Contrast((0.75, 1.25)),
Hue((-10, 10)),
])
DATASET.TRAIN_VALIDATION_SAVING_SIZE = 5000
8 changes: 7 additions & 1 deletion lmnet/executor/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,20 @@ def start_training(config):
)
)
else:
session_config = tf.ConfigProto(
gpu_options=tf.GPUOptions(
allow_growth=True
# visible_device_list=str(hvd.local_rank())
)
)
# TODO(wakisaka): For debug.
# session_config = tf.ConfigProto(
# gpu_options=tf.GPUOptions(
# allow_growth=True,
# per_process_gpu_memory_fraction=0.1
# )
# )
session_config = tf.ConfigProto() # tf.ConfigProto(log_device_placement=True)
# session_config = tf.ConfigProto() # tf.ConfigProto(log_device_placement=True)
# TODO(wakisaka): XLA JIT
# session_config.graph_options.optimizer_options.global_jit_level = tf.OptimizerOptions.ON_1

Expand Down
22 changes: 22 additions & 0 deletions lmnet/get-img-from-cifar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from six.moves import cPickle as pickle
from PIL import Image
import numpy as np
import scipy.misc

f = open('dataset/CIFAR_10/cifar-10-batches-py/data_batch_1', 'rb')

tupled_data= pickle.load(f, encoding='bytes')

f.close()

img = tupled_data[b'data']
label = tupled_data[b'labels']

for i in range(10):
single_img = np.array(img[i])
single_label = str(label[i])
single_img_reshaped = np.transpose(np.reshape(single_img,(3, 32,32)), (1,2,0))
scipy.misc.imsave(f'images/{i}-{single_label}.jpg',single_img_reshaped)
#single_img_reshaped = single_img.reshape(32,32,3)

#plt.imshow(single_img_reshaped)
Loading