shicai / densenet-caffe Goto Github PK
View Code? Open in Web Editor NEWDenseNet Caffe Models, converted from https://github.com/liuzhuang13/DenseNet
DenseNet Caffe Models, converted from https://github.com/liuzhuang13/DenseNet
Do you have Network definition in Python? Thanks!
When i use the pycaffe to prediction, according to readme subtract mean [103.94,116.78,123.68],but the result is bad.I also suspect that it is a label problem,so i follow the tips for another question,check the fb.resnet.torch/imagenet.lua at master · facebook/fb.resnet.torch have no problems.code as follows:
transformer=caffe.io.Transformer({'data':net.blobs['data'].data.shape})
transformer.set_transpose('data',(2,0,1))
transformer.set_mean('data',np.array([103.94,116.78,123.68]))
transformer.set_raw_scale('data',225)
transformer.set_channel_swap('data',(2,1,0))
So i tried to comment some preprocesss setting,when i comment thetransformer.set_mean
and transformer.set_raw_scale
,i found the prediction is very good.
I am very confused,train and test need to be consistent in general ??
I want to ask where the problem might be.
Looking forward to anyone’s reply, thank you!
Thanks for sharing the work. Do you use same parameter settings in the https://github.com/liuzhuang13/DenseNetCaffe for optimization? I ask it because the learning rate of the reference one is so high (about 0.1). In additions, do you get the performance using your prototxt it for CIFAR dataset? Thanks
i use it in caffe( and i ve add the ceil_mode into my code)
./build_release/examples/cpp_classification/classification.bin
models/DenseNet_shicai/DenseNet_201.prototxt
models/DenseNet_shicai/DenseNet_201.caffemodel
data/ilsvrc12/imagenet_mean.binaryproto \ ( i don't know whether it is that?)
data/ilsvrc12/synset_words.txt
imagenet/n02493509/n02493509_10160.JPEG
the result is:
38.6030 - "n06359193 web site, website, internet site, site"
36.7457 - "n02708093 analog clock"
........
........
........
I have tried a few pictures, the result seems to be very strange,.
could you tell me how to do with it ? Thanks.
Hi, shicai, these caffemodel which include in Baidu Disk can not download,can you share the Baidu Disk link again?thank you!
Hi, shicai, can i directly revise deploy.prototxt to get trainval.prototxt and what is the need to pay attention to detail?
Hi ,
Where Can I find the train_val.prototxt so that I can know the transformer params (preprocessing part)
Thanks
When loading this model with Chainer and attempting to evaluate a batch of images it complains that the eps param in batch-norm is < 1e-5
sym = caffe.CaffeFunction("DenseNet_121.caffemodel")
Is it possible to truncate it at 1e-5 without affecting the accuracy?
RuntimeError Traceback (most recent call last)
in ()
1 dta = fake_input_data_cf[:8]
----> 2 pred = sym(inputs={'data':dta}, outputs=['fc6'])/anaconda/envs/py35/lib/python3.5/site-packages/chainer/links/caffe/caffe_function.py in call(self, inputs, outputs, disable, **kwargs)
218 func = self.forwards[func_name]
219 input_vars = tuple(variables[blob] for blob in bottom)
--> 220 output_vars = func(*input_vars)
221 if not isinstance(output_vars, collections.Iterable):
222 output_vars = output_vars,/anaconda/envs/py35/lib/python3.5/site-packages/chainer/links/caffe/caffe_function.py in call(self, x)
567
568 def call(self, x):
--> 569 return self.func(x, *self.args, **self.kwargs)
570
571/anaconda/envs/py35/lib/python3.5/site-packages/chainer/links/caffe/caffe_function.py in call(self, *xs, **kwargs)
606
607 def call(self, *xs, **kwargs):
--> 608 return self.caffe_func[self.name](*xs, **kwargs)
609
610/anaconda/envs/py35/lib/python3.5/site-packages/chainer/links/normalization/batch_normalization.py in call(self, x, **kwargs)
142 ret = functions.batch_normalization(
143 x, gamma, beta, eps=self.eps, running_mean=self.avg_mean,
--> 144 running_var=self.avg_var, decay=decay)
145 else:
146 # Use running average statistics or fine-tuned statistics./anaconda/envs/py35/lib/python3.5/site-packages/chainer/functions/normalization/batch_normalization.py in batch_normalization(x, gamma, beta, **kwargs)
527 ('running_var', None), ('decay', 0.9))
528
--> 529 return BatchNormalization(eps, running_mean, running_var, decay).apply(
530 (x, gamma, beta))[0]
531/anaconda/envs/py35/lib/python3.5/site-packages/chainer/functions/normalization/batch_normalization.py in init(self, eps, mean, var, decay)
30 if eps < 1e-5:
31 msg = 'cuDNN does not allow an eps value less than 1e-5.'
---> 32 raise RuntimeError(msg)
33 self.decay = decay
34RuntimeError: cuDNN does not allow an eps value less than 1e-5.
Hello, Shicai. When generating train_val.prototxt from LiuZhuang13's code, the scope name will be "Convolution1", "BatchNorm13" etc., which is different from yours like "conv1/bn1", "conv3_2/x2/scale". I wonder that the difference will lead a failure to load the pre-train caffemodel. How to deal with the problem? And I will be very appreciated if you provide your make_densenet.py code. Thanks.
WARNING: Logging before InitGoogleLogging() is written to STDERR
W0805 10:26:38.720525 3101 _caffe.cpp:139] DEPRECATION WARNING - deprecated use of Python interface
W0805 10:26:38.720546 3101 _caffe.cpp:140] Use this instead (with the named "weights" parameter):
W0805 10:26:38.720549 3101 _caffe.cpp:142] Net('/home/xuy/桌面/code/python/caffe/Bag_gender_hair_classification/DenseNet_deploy_161.prototxt', 1, weights='/home/xuy/桌面/code/python/caffe/Bag_gender_hair_classification/model/DenseNet_161.caffemodel')
[libprotobuf ERROR google/protobuf/text_format.cc:245] Error parsing text-format caffe.NetParameter: 54:14: Message type "caffe.PoolingParameter" has no field named "ceil_mode".
F0805 10:26:38.740175 3101 upgrade_proto.cpp:88] Check failed: ReadProtoFromTextFile(param_file, param) Failed to parse NetParameter file: /home/xuy/桌面/code/python/caffe/Bag_gender_hair_classification/DenseNet_deploy_161.prototxt
*** Check failure stack trace: ***
Thanks for your job! I use your pretrain model and SSD algorithm to train a model.
for conv layer, I add param { lr_mult: 1 decay_mult: 1}
for bn layer , I add param { lr_mult: 0 decay_mult: 0} for 3 times to fix.
I don't konw the scale layer need add lr_mult and decay_mult?scale 层需要添加学习率这些参数吗
And for conv layer, need I add weight_filler and bias_filler? 我既然有了预训练模型,那还需要对卷积层参数初始化吗?
谢谢!
the following is my solver.prototxt:
net: "examples/re_identification/DenseNet_201.prototxt"
test_iter: 5000
test_interval: 1000
base_lr: 0.01
lr_policy: "step"
gamma: 0.1
stepsize: 1000
display: 20
max_iter: 10000
momentum: 0.9
weight_decay: 0.0005
snapshot: 1000
snapshot_prefix: "examples/re_identification/caffenet_train"
solver_mode: GPU
and i add some code in your DenseNet.prototxt
at the beginning:
name: "DENSENET_201"
layer {
name: "data"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
crop_size: 224
mean_value: 90
mean_value: 102
mean_value: 100
mirror: true
}
data_param {
source: "/home/zhou/caffe/examples/re_identification/img_train_lmdb"
batch_size: 1
backend: LMDB
}
}
layer {
name: "data"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
crop_size: 224
mean_value: 90
mean_value: 102
mean_value: 100
mirror: false
}
data_param {
source: "/home/zhou/caffe/examples/re_identification/img_test_lmdb"
batch_size: 1
backend: LMDB
}
}
layer {
name: "conv1"
type: "Convolution"
bottom: "data"
top: "conv1"
convolution_param {
num_output: 64
bias_term: false
pad: 3
kernel_size: 7
stride: 2
}
...
...
...
at the end i add:
layer {
name: "fc6"
type: "Convolution"
bottom: "pool5"
top: "fc6"
convolution_param {
num_output: 1000
kernel_size: 1
}
}
layer {
name: "accuracy"
type: "Accuracy"
bottom: "fc6"
bottom: "label"
top: "accuracy"
include {
phase: TEST
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "fc6"
bottom: "label"
top: "loss"
}
and the label of my dataset is 0 to 999
i do not know why my loss is not decrease and keep the value about 6.9
First of all, thanks for sharing these models. I am not quite understand what this scale ratio means. Do I have to implement this on the input data or what?
Thanks
Thanks for sharing!
I want to fine-tuning the model. Is there train-val.prototxt and solver.prototxt survive? Thank you.
您好,在densenet训练阶段,train.prototxt中是否要设置BN层在TRAIN和TEST两种phase下的参数use_global_stats的状态,例如这样:
layer {
bottom: "conv6"
top: "conv6"
name: "bn_conv6"
type: "BatchNorm"
batch_norm_param {
use_global_stats: false
}
include {
phase: TRAIN
}
}
layer {
bottom: "conv6"
top: "conv6"
name: "bn_conv6"
type: "BatchNorm"
batch_norm_param {
use_global_stats: true
}
include{
phase: TEST
}
}
还是说只需要设置一种状态,然后在deploy.prototxt中,设置use_global_stats=true就行了
Nice work!
However, I found that ceil_mode is not supported in the master version of caffe.
Is there an open-sourced caffe version that supports ceil_mode in pooing? Thanks.
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0324 10:41:30.693701 10280 common.cpp:36] System entropy source not available, using fallback algorithm to generate seed instead.
W0324 10:41:30.751742 10280 _caffe.cpp:122] DEPRECATION WARNING - deprecated use of Python interface
W0324 10:41:30.751742 10280 _caffe.cpp:123] Use this instead (with the named "weights" parameter):
W0324 10:41:30.751742 10280 _caffe.cpp:125] Net('net.prototxt', 0, weights='exp/mnist/save_iter_100000.caffemodel')
[libprotobuf ERROR ..\src\google\protobuf\text_format.cc:274] Error parsing text-format caffe.NetParameter: 7:13: Message type "caffe.DataParameter" has no field named "seek".
*** Check failure stack trace: ***
您好,有个问题想请教一下。在每个Dense Block中,每个3332的conv前面都接了11128的conv,这样接比不接11128的计算量还要大,因为channel数目增多了,那为什么要这么做呢?
The DenseNet prototxts are wonderful. Thanks so much!
Hi @shicai ,
I followed Resnet policy for training Densenet-121 yet get 72% for top1, I'd be appreciated if there is any tricks to share to reach the paper acc.
Btw due to the GPU limit, I could only train with a batchsize 64.
Thx!
Hi, I am training Densenet-121. When the batch size is larger than about 25, out of memory occurs. I'm using a work station with 8 TITANXPascal GPUs, so I can't achieve batch size larger than 200...
What's your batch size when you trained these nets?
when i download the model i cant download the whole model
I saw that you use a convolution layer instead of an innerproduct layer for "fc6". Though it looks weird I am okay with that.
So I added a softmax layer after fc6 to perform classification on my own testing image (it's a cat image). But the model failed to predict the correct class. It might be due to 2 reasons:
im[:,:,0] = (im[:,:,0] - 103.94) / 0.017
im[:,:,1] = (im[:,:,1] - 116.78) / 0.017
im[:,:,2] = (im[:,:,2] - 123.68) / 0.017
Hi,
Are these networks DenseNet-BC?
Thanks.
Loading .caffemodel
and deploy.ptototxt
in caffe for TEST
phase returns the following error:
[libprotobuf ERROR google/protobuf/text_format.cc:288] Error parsing text-format caffe.NetParameter: 54:14: Message type "caffe.PoolingParameter" has no field named "ceil_mode".
F0430 20:48:24.400027 24399 upgrade_proto.cpp:90] Check failed: ReadProtoFromTextFile(param_file, param) Failed to parse NetParameter file: MODELS/DenseNet161/ImageNet/deploy.prototxt
*** Check failure stack trace: ***
Aborted (core dumped
ur Baidu link (https://pan.baidu.com/s/1gfjD8cF) seems to be broken too! Do u have updated version of that link?
I have tried the version which have vision_layers.hpp and add those lines which "shicai" asked.but it didn't work.please send me a caffe-master ,if u can run it.
想将该DenseNet121模型作为Faster R-CNN的基础网络去实现,基于您给的DenseNet_121.prototxt文件做了如下修改来生成train.prototxt
1. 数据输入按照Faster R-CNN的去写
2. 对于conv layers ,添加1次{ lr_mult: 1 decay_mult: 1}
3. 对于batchnorm layers,添加3次 {lr_mult: 0 decay_mult: 0}
4. 对于scale layers,添加2次param {lr_mult: 1 decay_mult: 0}
5. RPN,ROI Proposal, RCNN,这3部分基本照搬Faster R-CNN中VGG16的去写.做了如下修改:
1. RPN部分的bottom改为:conv4_blk
2. R-CNN部分的bottom改为:conv5_blk/bn"
3. R-CNN部分原来的fc6层改名为fc6_1
您给的prototxt文件中的"最后的fc6层"和"倒数第2个Pooling层"我直接删除了
其他的基本没变.现有如何疑问:
1. 不知道上述那样的修改是否妥当??
2. 对于Faster R-CNN中的test.prototxt,输入,RPN,ROI Proposal, RCNN这4部分还是按照Faster R-CNN中VGG16的去写.但对于中间的网络部分怎么修改??也要像2,3,4步那样去修改增加对应的param吗??
3. solver文件怎么写,有没有一些参考??我这里基本是照搬Faster R-CNN中VGG16的.
In pool1, the input spatial shape is 112 and ceil_mode = false.
So the output shape will be floor((112-3+2)/2+1) = 56
Does this equal to "padding = 'SAME'" in tensorflow? Which output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides[i])
对于卷积层:
当设置param{ lr_mult: X}时,相当于该层的学习率为solver中的base_lr乘以这个系数X
当设置param{ lr_mult: 0}时,相当于固定该层的权重,不用学习
当没有设置param{ lr_mult:}时,相当于该层的学习率为solver中的base_lr
可以这么理解吗??发现很多prototxt中并没有这个参数param.
Dear Shicai,
I'm trying to fine-tune my dataset using your model. I've already read all the issues and make some modification to .prototxt , but it gives me the following error:
ERROR: Check failed: target_blobs.size() == source_layer.blobs_size() (5 vs. 3) Incompatible number of blobs for layer conv1/bn
would you please help me to find the problem?
here is my proto , I'm using AWS P3 instance and using Digits.
layer {
name: "train-data"
type: "Data"
top: "data"
top: "label"
include {
stage: "train"
}
transform_param {
crop_size: 224
}
data_param {
batch_size: 126
}
}
layer {
name: "val-data"
type: "Data"
top: "data"
top: "label"
include {
stage: "val"
}
transform_param {
crop_size: 224
}
data_param {
batch_size: 64
}
}
layer {
name: "conv1"
type: "Convolution"
bottom: "data"
top: "conv1"
convolution_param {
num_output: 64
bias_term: false
pad: 3
kernel_size: 7
stride: 2
}
}
layer {
name: "conv1/bn"
type: "BatchNorm"
bottom: "conv1"
top: "conv1/bn"
batch_norm_param {
eps: 1e-5
}
}
layer {
name: "conv1/scale"
type: "Scale"
bottom: "conv1/bn"
top: "conv1/bn"
scale_param {
bias_term: true
}
}
layer {
name: "relu1"
type: "ReLU"
bottom: "conv1/bn"
top: "conv1/bn"
}
.
.
.
.
layer {
name: "fc6new"
type: "Convolution"
bottom: "pool5"
top: "fc6new"
convolution_param {
num_output: 35
kernel_size: 1
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "fc6new"
bottom: "label"
top: "loss"
exclude {
stage: "deploy"
}
}
layer {
name: "accuracy"
type: "Accuracy"
bottom: "fc6new"
bottom: "label"
top: "accuracy"
include {
stage: "val"
}
}
layer {
name: "accuracy_train"
type: "Accuracy"
bottom: "fc6new"
bottom: "label"
top: "accuracy_train"
include {
stage: "train"
}
accuracy_param {
top_k: 5
}
}
layer {
name: "softmax"
type: "Softmax"
bottom: "fc6new"
top: "softmax"
include {
stage: "deploy"
}
}
the complete error thrown by digits
conv2_1/x2/bn needs backward computation.
conv2_1/x1 needs backward computation.
relu2_1/x1 needs backward computation.
conv2_1/x1/scale needs backward computation.
conv2_1/x1/bn needs backward computation.
pool1_pool1_0_split needs backward computation.
pool1 needs backward computation.
relu1 needs backward computation.
conv1/scale needs backward computation.
conv1/bn needs backward computation.
conv1 needs backward computation.
label_val-data_1_split does not need backward computation.
val-data does not need backward computation.
This network produces output accuracy
This network produces output loss
Network initialization done.
Solver scaffolding done.
Finetuning from /home/ubuntu/models/DenseNet-Caffe/densenet201.caffemodel
Ignoring source layer input
Check failed: target_blobs.size() == source_layer.blobs_size() (5 vs. 3) Incompatible number of blobs for layer conv1/bn
In my opinion, in order to 2 classification,I should add the probability which type is softmax to achieve it.but I find that in your DenseNet_121.prototxt file,I could not find the softmax layer.So in order to achieve the 2 classification,what should I do to output the probability,and what should I do to achieve 2 classification
Error parsing text-format caffe.NetParameter: 54:14: Message type "caffe.PoolingParameter" has no field named "ceil_mode".
It seem that you have modified caffe source code which have no ceil_mode.
How can I fix it?
Thanks
Hi, thanks for your work!
I follow your instruction and run DenseNet121 but only get 0.715681 top-1 accuracy and 0.904023 top-5 accuracy.
I guess it may be caused by the dataset. I use val_lmdb(ressize to 256x256) and crop to 224x224 in the train.prototxt for testing. But for you, it's here:
The top-1/5 accuracy rates by using single center crop (crop size: 224x224, image size: 256xN).
Do you use the original val images for testing? I really don't know what to do to produce 256xN image size.
I find your another reply about image_size here: http://www.caffecn.cn/?/question/428
I get more confused about 10 crops. Can you take a minute to explain it to me?
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.