nolanliou / mobile-deeplab-v3-plus Goto Github PK
View Code? Open in Web Editor NEWDeeplab-V3+ model with MobilenetV2/MobilenetV3 on TensorFlow for mobile deployment.
License: MIT License
Deeplab-V3+ model with MobilenetV2/MobilenetV3 on TensorFlow for mobile deployment.
License: MIT License
i use the 256model ,output picture is not right,
Hi.
I would like to evaluate the performance of segmentation in our environment and have tried to create a model following the instructions but without success.
I'm trying to correct the current error, but if possible, could you please give me the generated model?
Thanks.
INFO:tensorflow:Restoring parameters from /root/mobile-deeplab-v3-plus/datasets/people_segmentation/exp/deeplab-v3-plus/train/model.ckpt-0
INFO:tensorflow:Running local_init_op.
INFO:tensorflow:Done running local_init_op.
INFO:tensorflow:Saving checkpoints for 0 into /root/mobile-deeplab-v3-plus/datasets/people_segmentation/exp/deeplab-v3-plus/train/model.ckpt.
INFO:tensorflow:loss = 1.0444846, step = 0
INFO:tensorflow:cross_entropy = 0.6935922, learning_rate = 1e-04, total_loss = 1.0444846, train_mean_iou = 0.32585338, train_pixel_accuracy = 0.4993496
ERROR:tensorflow:Model diverged with loss = NaN.
Traceback (most recent call last):
File "run.py", line 552, in <module>
tf.app.run()
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "run.py", line 539, in main
train()
File "run.py", line 433, in train
tf.estimator.train_and_evaluate(model, train_spec, eval_spec)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/training.py", line 471, in train_and_evaluate
return executor.run()
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/training.py", line 610, in run
return self.run_local()
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/training.py", line 711, in run_local
saving_listeners=saving_listeners)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py", line 356, in train
return self
File "/usr/lib/python3.5/contextlib.py", line 77, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/eager/context.py", line 357, in _mode
yield
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py", line 354, in train
loss = self._train_model(input_fn, hooks, saving_listeners)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py", line 1207, in _train_model
return self._train_model_default(input_fn, hooks, saving_listeners)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py", line 1241, in _train_model_default
saving_listeners)
File "/usr/lib/python3.5/contextlib.py", line 77, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 5229, in get_controller
yield g
File "/usr/lib/python3.5/contextlib.py", line 77, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 5037, in get_controller
yield default
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 5229, in get_controller
yield g
File "/usr/lib/python3.5/contextlib.py", line 77, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/eager/context.py", line 357, in _mode
yield
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 5229, in get_controller
yield g
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py", line 1241, in _train_model_default
saving_listeners)
File "/usr/lib/python3.5/contextlib.py", line 77, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 4247, in device
yield
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py", line 1241, in _train_model_default
saving_listeners)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py", line 1471, in _train_with_estimator_spec
_, loss = mon_sess.run([estimator_spec.train_op, estimator_spec.loss])
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/monitored_session.py", line 671, in run
run_metadata=run_metadata)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/monitored_session.py", line 1156, in run
run_metadata=run_metadata)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/monitored_session.py", line 1255, in run
raise six.reraise(*original_exc_info)
File "/usr/local/lib/python3.5/dist-packages/six.py", line 693, in reraise
raise value
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/monitored_session.py", line 1240, in run
return self._sess.run(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/monitored_session.py", line 1320, in run
run_metadata=run_metadata))
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/basic_session_run_hooks.py", line 753, in after_run
raise NanLossDuringTrainingError
tensorflow.python.training.basic_session_run_hooks.NanLossDuringTrainingError: NaN loss during training.
I am suffering to run this code using person segmentation dataset.
Can't solve the 'NaN loss during training' error and I didn't edit any parameter.
How to fix it?
I write test model code, but the model output is not mask, there is no result as shown in the picture below, Can you tell me how to get the visualization result in the picture below.My email is: [email protected]
` return colormap[label]
def write_result(imagefile, imgname, outputDir):
#!---- coding:utf-8 ----
import os
import numpy as np
from PIL import Image
import tempfile
from six.moves import urllib
class DeepLabModel(object):
"""
加载 DeepLab 模型;
推断 Inference.
"""
INPUT_TENSOR_NAME = 'Input:0'
OUTPUT_TENSOR_NAME = 'Output:0'
INPUT_SIZE = 513
FROZEN_GRAPH_NAME = 'frozen_inference_graph'
def __init__(self, tarball_path):
""" def __init__(self, tarball_path):
"""
Creates deeplab model.
"""
self.graph = tf.Graph()
#graph_def = None
graph_def = tf.GraphDef.FromString(open(tarball_path, 'rb').read())
if graph_def is None:
raise RuntimeError('Cannot find inference graph in tar archive.')
with self.graph.as_default():
tf.import_graph_def(graph_def, name='')
self.sess = tf.Session(graph=self.graph)
def run(self, image):
"""
Runs inference on a single image.
Args:
image: A PIL.Image object, raw input image.
Returns:
resized_image: RGB image resized from original input image.
seg_map: Segmentation map of `resized_image`.
"""
width, height = image.size
resize_ratio = 1.0 * self.INPUT_SIZE / max(width, height)
target_size = (int(resize_ratio * width), int(resize_ratio * height))
resized_image = image.convert('RGB').resize(target_size, Image.ANTIALIAS)
batch_seg_map = self.sess.run(self.OUTPUT_TENSOR_NAME,
feed_dict={self.INPUT_TENSOR_NAME: [np.asarray(resized_image)]})
seg_map = batch_seg_map[0]
return resized_image, seg_map
def create_pascal_label_colormap():
"""
Creates a label colormap used in PASCAL VOC segmentation benchmark.
Returns:
A Colormap for visualizing segmentation results.
"""
colormap = np.zeros((256, 3), dtype=int)
ind = np.arange(256, dtype=int)
for shift in reversed(range(8)):
for channel in range(3):
colormap[:, channel] |= ((ind >> channel) & 1) << shift
ind >>= 3
return colormap
def label_to_color_image(label):
"""
Adds color defined by the dataset colormap to the label.
Args:
label: A 2D array with integer type, storing the segmentation label.
Returns:
result: A 2D array with floating type. The element of the array
is the color indexed by the corresponding element in the input label
to the PASCAL color map.
Raises:
ValueError: If label is not of rank 2 or its value is larger than color
map maximum entry.
"""
if label.ndim != 2:
raise ValueError('Expect 2-D input label')
colormap = create_pascal_label_colormap()
if np.max(label) >= len(colormap):
raise ValueError('label value too large.')
return colormap[label]
def write_result(imagefile, imgname, outputDir):
orignal_im = Image.open(imagefile)
print('running deeplab on image %s...' % imagefile)
resized_im, seg_map = MODEL.run(orignal_im)
seg_image = label_to_color_image(seg_map).astype(np.uint8)
img_path = os.path.join(outputDir, imgname)
cv2.imwrite(img_path, seg_image)
`
Hi!
I used the pretrained MobileNetV2 513x513 model and first analyzed it with summarize_graph tool which gave me the following output:
Found 1 possible inputs: (name=Input, type=float(1), shape=[?,513,513,3]) No variables spotted. Found 1 possible outputs: (name=Output, op=ExpandDims)
Then I converted this model to tflite, which was successful.
Then I tried to used that in my Android app with no success.
` private static final float IMAGE_MEAN = 128.0f;
private static final float IMAGE_STD = 128.0f;
private final static int INPUT_SIZE = 513;
private final static int NUM_CLASSES = 2;
private final static int COLOR_CHANNELS = 3;
private final static int BYTES_PER_POINT = 4;
...
mImageData = ByteBuffer.allocateDirect(
1 * INPUT_SIZE * INPUT_SIZE * COLOR_CHANNELS * BYTES_PER_POINT);
mImageData.order(ByteOrder.nativeOrder());
mOutputs = ByteBuffer.allocateDirect(1 * INPUT_SIZE * INPUT_SIZE * NUM_CLASSES * BYTES_PER_POINT_OUT);
`
first there was a buffer size mismatch between my mOutputs buffer the output buffer from tensorflow lite.
What is the shape and the name of the output model?
Also, when I used the frozen inference graph without tflite conversion I still didn't have success. I used it in python. The output was all black, 0 person pixels.
I tried the demo on the android app using the provided pre trained models. But the cutout is not accurate
How to increase the accuracy of the mask?
Is it possible to train a lot more and get results like remove.bg?
@nolanliou
Hi, I have trained deeplab on my custom dataset(200*150) with 224 as crop size and during the test, it detects for crop with crop size 224 .
now what I need is to integrate my model on ios application, i was able to successfully convert the model to tflite .but it doesn't detect anything i don't get it whats the problem
because when i tried to convert a deeplab pretrained mobilenet that you have mentioned it works for me on mobile and for my model no ,however, i have tested my model (.pb model)with python code and it detects
did you have any idea??
I write test model code, but the model output is not mask, there is no result as shown in the picture below, can you tell me how to get
---- coding:utf-8 ----
import os
import numpy as np
from PIL import Image
import tempfile
from six.moves import urllib
import tensorflow as tf
import cv2
import time
class DeepLabModel(object):
"""
加载 DeepLab 模型;
推断 Inference.
"""
INPUT_TENSOR_NAME = 'Input:0'
OUTPUT_TENSOR_NAME = 'Output:0'
INPUT_SIZE = 513
FROZEN_GRAPH_NAME = 'frozen_inference_graph'
def __init__(self, tarball_path):
"""
Creates deeplab model.
"""
self.graph = tf.Graph()
When I run run.sh, it appears the problem as title.
It seems that /utils lost many py files, it possible, please add these files to it.
Thant you!
hi,
how can I get the whole People Segmentation dataset
thank you
where is the android project about it, thanks a lot.
I have downloaded the graph file(.pb) which you given into .tflite file..
I want to use this model in flutter app. Model is loaded successfully but the app crashes when I send an image to the model..
Bellow code I used for sending an image.
var recognitions = await Tflite.runSegmentationOnImage( path: image.path, //imageMean: 127.5, //imageStd: 127.5, //outputType: "JPG" );
Flutter package which I used.
https://pub.dev/packages/tflite
Hi, I want to use the model to do prediction task, could you tell me how to do that?
Thanks very much!
I write test model code, but the model output is not mask, there is no result as shown in the picture below, can you tell me how to get
` return colormap[label]
def write_result(imagefile, imgname, outputDir):
#!---- coding:utf-8 ----
import os
import numpy as np
from PIL import Image
import tempfile
from six.moves import urllib
class DeepLabModel(object):
"""
加载 DeepLab 模型;
推断 Inference.
"""
INPUT_TENSOR_NAME = 'Input:0'
OUTPUT_TENSOR_NAME = 'Output:0'
INPUT_SIZE = 513
FROZEN_GRAPH_NAME = 'frozen_inference_graph'
def __init__(self, tarball_path):
""" def __init__(self, tarball_path):
"""
Creates deeplab model.
"""
self.graph = tf.Graph()
#graph_def = None
graph_def = tf.GraphDef.FromString(open(tarball_path, 'rb').read())
if graph_def is None:
raise RuntimeError('Cannot find inference graph in tar archive.')
with self.graph.as_default():
tf.import_graph_def(graph_def, name='')
self.sess = tf.Session(graph=self.graph)
def run(self, image):
"""
Runs inference on a single image.
Args:
image: A PIL.Image object, raw input image.
Returns:
resized_image: RGB image resized from original input image.
seg_map: Segmentation map of `resized_image`.
"""
width, height = image.size
resize_ratio = 1.0 * self.INPUT_SIZE / max(width, height)
target_size = (int(resize_ratio * width), int(resize_ratio * height))
resized_image = image.convert('RGB').resize(target_size, Image.ANTIALIAS)
batch_seg_map = self.sess.run(self.OUTPUT_TENSOR_NAME,
feed_dict={self.INPUT_TENSOR_NAME: [np.asarray(resized_image)]})
seg_map = batch_seg_map[0]
return resized_image, seg_map
def create_pascal_label_colormap():
"""
Creates a label colormap used in PASCAL VOC segmentation benchmark.
Returns:
A Colormap for visualizing segmentation results.
"""
colormap = np.zeros((256, 3), dtype=int)
ind = np.arange(256, dtype=int)
for shift in reversed(range(8)):
for channel in range(3):
colormap[:, channel] |= ((ind >> channel) & 1) << shift
ind >>= 3
return colormap
def label_to_color_image(label):
"""
Adds color defined by the dataset colormap to the label.
Args:
label: A 2D array with integer type, storing the segmentation label.
Returns:
result: A 2D array with floating type. The element of the array
is the color indexed by the corresponding element in the input label
to the PASCAL color map.
Raises:
ValueError: If label is not of rank 2 or its value is larger than color
map maximum entry.
"""
if label.ndim != 2:
raise ValueError('Expect 2-D input label')
colormap = create_pascal_label_colormap()
if np.max(label) >= len(colormap):
raise ValueError('label value too large.')
return colormap[label]
def write_result(imagefile, imgname, outputDir):
orignal_im = Image.open(imagefile)
print('running deeplab on image %s...' % imagefile)
resized_im, seg_map = MODEL.run(orignal_im)
seg_image = label_to_color_image(seg_map).astype(np.uint8)
img_path = os.path.join(outputDir, imgname)
cv2.imwrite(img_path, seg_image)
`
thanks for your sharing hard works
I can't download the file of pretrained_mobilenet_v2_1.0_224.tar.gz, can you sent me one,or tell me the reasion the why i can not download,thansk !
download website is :http://cnbj1-fds.api.xiaomi.net/code/models/pretrained_mobilenet_v2_1.0_224.tar.gz
error is : 无法访问此网站 网址为 http://cnbj1-fds.api.xiaomi.net/code/models/pretrained_mobilenet_v2_1.0_224.tar.gz 的网页可能暂时无法连接,或者它已永久性地移动到了新网址。
ERR_INVALID_RESPONSE
i had download one from the internet ,but i want to know the resions,thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.