我对神经网络中“主干”的含义感到困惑,尤其是在DeepLabv3+ 论文中。我做了一些研究,发现骨干可能意味着
网络的特征提取部分
DeepLabv3+ 以Xception和 ResNet-101 作为其主干。但是,我对DeepLabv3+的整个结构并不熟悉,主干指的是哪部分,哪些部分保持不变?
主干的一般描述或定义也将受到赞赏。
按照模型中包含的说明,--training_crop_size将其设置为远小于训练图像大小的值。例如:
python deeplab/train.py \
--logtostderr \
--training_number_of_steps=90000 \
--train_split="train" \
--model_variant="xception_65" \
--atrous_rates=6 \
--atrous_rates=12 \
--atrous_rates=18 \
--output_stride=16 \
--decoder_output_stride=4 \
--train_crop_size="769,769" \
--train_batch_size=1 \
--dataset="cityscapes" \
--tf_initial_checkpoint=${PATH_TO_INITIAL_CHECKPOINT} \
--train_logdir=${PATH_TO_TRAIN_DIR} \
--dataset_dir=${PATH_TO_DATASET}
Run Code Online (Sandbox Code Playgroud)
但是这个选项实际上有什么作用呢?是否需要随机裁剪每个训练图像?如果是这样,输入尺寸会不会更小,例如,例如 769x769 (WxH)?根据说明,评估裁剪大小设置为 2049x1025。当没有调整图像大小的建议时,输入尺寸为 769x769 的网络如何接受 2049x1025 输入?会出现形状不匹配的问题。
说明有冲突吗?
我们正在尝试使用deeplabv3和mobilenetv2在android上运行语义分割模型,并在bazel的帮助下使用TOCO和tflite_convert遵循了官方的tensorflow lite转换过程。
我们能够使用以下命令成功转换模型:
CUDA_VISIBLE_DEVICES =“ 0” toco --output_file = toco256.tflite --graph_def_file = path / to / deeplab / deeplabv3_mnv2_pascal_trainval / frozen_inference_graph.pb --input_arrays = ImageTensor --output_arrays = SemanticPredictions --Input_shape,= 3,mn_2 --inference_type = FLOAT-平均值= 128 --std_dev_values = 127 --allow_custom_ops --post_training_quantize
tflite文件的大小约为2.25 Mb,但是当我们尝试使用官方基准工具测试模型时,它失败并显示以下错误报告:-
bazel run -c opt tensorflow/contrib/lite/tools/benchmark:benchmark_model -- --graph=`realpath toco256.tflite`
INFO: Analysed target //tensorflow/contrib/lite/tools/benchmark:benchmark_model (0 packages loaded).
INFO: Found 1 target...
Target //tensorflow/contrib/lite/tools/benchmark:benchmark_model up-to-date:
bazel-bin/tensorflow/contrib/lite/tools/benchmark/benchmark_model
INFO: Elapsed time: 0.154s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action …Run Code Online (Sandbox Code Playgroud) 在将转换后的TFLite模型加载到android应用程序时遇到问题。
型号:Deeplabv3 Mobilenetv2(在Pascal VOC上进行了培训)TFLite版本:1.10
使用tflite_convert将pb文件转换为tflite。(Tensorflow版本:1.11.0)
码:
private MappedByteBuffer loadModelFile(AssetManager assets, String modelFilename)
throws IOException {
AssetFileDescriptor fileDescriptor = assets.openFd(modelFilename);
FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor());
FileChannel fileChannel = inputStream.getChannel();
long startOffset = fileDescriptor.getStartOffset();
long declaredLength = fileDescriptor.getDeclaredLength();
return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength);
}
/**
* Initializes a native TensorFlow session for classifying images.
*
* @param assetManager The asset manager to be used to load assets.
* @param modelFilename The filepath of the model GraphDef protocol buffer.
*/
public static Segmentor create( …Run Code Online (Sandbox Code Playgroud) 我首先解释一下我的任务:我从两条不同的绳索上获得了近3000张图像。它们包含绳索1,绳索2和背景。我的标签/遮罩是图像,例如像素值0表示背景,像素值1表示第一根绳子,而2表示第二根绳子。您可以在下面的图片1和2中看到输入图片和地面真理/标签。请注意,我的地面真相/标签只有3个值:0、1和2。我的输入图片是灰色的,但对于DeepLab,我将其转换为RGB图片,因为DeepLab是在RGB图片上训练的。但是我转换后的图片仍然不包含颜色。
该任务的思想是神经网络应该从绳索中学习结构,因此即使有knote,它也可以正确标记绳索。因此颜色信息并不重要,因为我的绳索具有不同的颜色,因此可以很容易地使用KMeans创建地面真相/标签。
为此,我在Keras中选择了一个名为DeepLab V3 +的语义分割网络,并以TensorFlow作为后端。我想用我的近3000张图像训练NN。图片的大小小于100MB,均为300x200像素。也许DeepLab并不是我的任务的最佳选择,因为我的图片不包含颜色信息并且图片的尺寸很小(300x200),但是到目前为止,我没有找到更好的语义分割NN。
从Keras网站,我知道如何使用flow_from_directory加载数据以及如何使用fit_generator方法。我不知道我的代码是否逻辑正确...
这里是链接:
https://keras.io/preprocessing/image/
https://keras.io/models/model/
https://github.com/bonlime/keras-deeplab-v3-plus
我的第一个问题是:
在我的实现中,我的图形卡几乎使用了所有内存(11GB)。我不知道为什么 DeepLab的权重可能有那么大吗?我的Batchsize默认为32,我所有的近300张图像都小于100MB。我已经使用过config.gpu_options.allow_growth = True代码,请参见下面的代码。
一般问题:
有人知道我的任务有很好的语义分割NN吗?我不需要经过彩色图像训练的神经网络。但是我也不需要NN,它是用二进制地面真实图片训练的...我用DeepLab测试了我的原始彩色图像(图片3),但是我得到的结果标签不好...
到目前为止,这是我的代码:
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "3"
import numpy as np
from model import Deeplabv3
import tensorflow as tf
import time
import tensorboard
import keras
from keras.preprocessing.image import img_to_array
from keras.applications import imagenet_utils
from keras.preprocessing.image import ImageDataGenerator
from keras.callbacks import TensorBoard
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.Session(config=config)
from keras import backend as K
K.set_session(session)
NAME = "DeepLab-{}".format(int(time.time()))
deeplab_model = Deeplabv3(input_shape=(300,200,3), classes=3) …Run Code Online (Sandbox Code Playgroud) 我尝试使用 DeepLab v3+ 进行语义分割,但结果全黑。
我删除了原始文件,并将原始数据分别放在 ImageSets/,JPEGImages/ 和 SegmentationClass/ 中。
我根据 PASCAL VOC 2012 颜色的规则准备了 SegmentationClassRaw 图像。
我编辑了 build_voc2012_data.py 和 segmenting_dataset.py
[build_voc2012_data.py]
FLAGS = tf.app.flags.FLAGS
tf.app.flags.DEFINE_string('image_folder',
'./VOCdevkit/VOC2012/JPEGImages',
'Folder containing images.')
tf.app.flags.DEFINE_string(
'semantic_segmentation_folder',
'./VOCdevkit/VOC2012/SegmentationClassRaw',
'Folder containing semantic segmentation annotations.')
tf.app.flags.DEFINE_string(
'list_folder',
'./VOCdevkit/VOC2012/ImageSets/Segmentation',
'Folder containing lists for training and validation')
tf.app.flags.DEFINE_string(
'output_dir',
'./tfrecord',
'Path to save converted SSTable of TensorFlow examples.')
_NUM_SHARDS = 4
# add -->>
FLAGS.image_folder = "./pascal_voc_seg/VOCdevkit/VOC2012/JPEGImages"
FLAGS.semantic_segmentation_folder = "./pascal_voc_seg/VOCdevkit/VOC2012/SegmentationClassRaw"
FLAGS.list_folder = "./pascal_voc_seg/VOCdevkit/VOC2012/ImageSets/Segmentation"
FLAGS.image_format = "png"
FLAGS.output_dir = "./pascal_voc_seg/tfrecord"
# …Run Code Online (Sandbox Code Playgroud) segmentation-fault deep-learning tensorflow semantic-segmentation deeplab
我想为 Deeplab v3 添加自定义损失,它不仅适用于热编码标签,而且适用于显着性预测。因此,您在下面看到的不是 Deeplab 损失实现:
label = tf.to_int32(label > 0.2)
one_hot_labels = slim.one_hot_encoding(label, num_classes, on_value=1.0, off_value=0.0)
tf.losses.softmax_cross_entropy(one_hot_labels, logits)
Run Code Online (Sandbox Code Playgroud)
我使用了这个实现:
softmax = tf.log(tf.nn.softmax(logits))
cross_entropy = -tf.reduce_sum(label*softmax, reduction_indices=[1])
tf.losses.add_loss(tf.reduce_mean(cross_entropy))
Run Code Online (Sandbox Code Playgroud)
用 5 张图像训练了大约 1000 个 epoch 并得到了这个结果:
此外,尝试了几种学习率,但它不会改变自定义损失的结果。
使用 Anaconda 尝试设置 deeplab ( https://github.com/tensorflow/models/tree/master/research/deeplab )。
通过看到其他问题的回答,我已经解决了很多问题,但遇到了一个似乎没有答案的问题:
尝试运行“python deeplab/model_test.py”时,我得到:
(base) PS D:\DeepLab\models-master\research> python deeplab/model_test.py
C:\Users\Jake\anaconda3\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\Users\Jake\anaconda3\lib\site-packages\tensorflow\python\framework\dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = …Run Code Online (Sandbox Code Playgroud) Deeplab v3 返回缩小/调整大小的图像及其相应的掩码。如何调整图像及其相应蒙版的大小以更好地符合我的规范。