Caffe HDF5神经网络基础实例解析模型文件失败
Caffe HDF5 neural network basic example fails to parse the model file
我正在尝试使用我使用 caffe 库从 CSV 文件准备的 HDF5 数据构建神经网络的最小示例。
我的原文如下:[wine_train.prototxt]
name:"wineclass"
layers {
name: "data"
type: "HDF5Data"
top: "data"
top: "label"
hdf5_data_param {
source: "examples/wine/test.txt"
batch_size: 10
}
include{
phase:TEST
}
}
layer {
name: "data"
type: "HDF5Data"
top: "label"
top: "label"
hdf5_data_param {
source: "examples/wine/train.txt"
batch_size: 2
}
include{
phase:TRAIN
}
}
layers {
name: "ip"
type: "INNER_PRODUCT"
bottom: "data"
top: "ip"
inner_product_param {
num_output: 3
}
}
layers {
name: "loss"
type: "SOFTMAX_LOSS"
bottom: "ip"
bottom: "label"
top: "loss"
}
layer {
name: "accuracy"
type: "Accuracy"
bottom: "ip"
bottom: "label"
top: "accuracy"
include {
phase: TEST
}
}
我的求解器如下:
net: "examples/wine/wine_train.prototxt"
test_iter: 250
test_interval: 1000
base_lr: 0.01
lr_policy: "step"
gamma: 0.1
stepsize: 5000
display: 1000
max_iter: 10000
momentum: 0.9
weight_decay: 0.0005
snapshot: 10000
snapshot_prefix: "wine/train"
solver_mode: CPU
每次我收到以下错误:
shaunak@ubuntu:~/caffe$ build/tools/caffe train -model '/home/shaunak/caffe/examples/wine/wine_train.prototxt' -solver '/home/shaunak/caffe/examples/wine/solver.prototxt'
I0415 04:31:00.154145 57047 caffe.cpp:117] Use CPU.
I0415 04:31:00.154485 57047 caffe.cpp:121] Starting Optimization
I0415 04:31:00.154552 57047 solver.cpp:32] Initializing solver from parameters:
test_iter: 250
test_interval: 1000
base_lr: 0.01
display: 1000
max_iter: 10000
lr_policy: "step"
gamma: 0.1
momentum: 0.9
weight_decay: 0.0005
stepsize: 5000
snapshot: 10000
snapshot_prefix: "wine/train"
solver_mode: CPU
net: "examples/wine/wine_train.prototxt"
I0415 04:31:00.154660 57047 solver.cpp:70] Creating training net from net file: examples/wine/wine_train.prototxt
[libprotobuf ERROR google/protobuf/text_format.cc:245] Error parsing text-format caffe.NetParameter: 4:9: Expected integer or identifier.
F0415 04:31:00.154774 57047 upgrade_proto.cpp:928] Check failed: ReadProtoFromTextFile(param_file, param) Failed to parse NetParameter file: examples/wine/wine_train.prototxt
*** Check failure stack trace: ***
@ 0x7f4a30766c3c google::LogMessage::Fail()
@ 0x7f4a30766b88 google::LogMessage::SendToLog()
@ 0x7f4a3076658a google::LogMessage::Flush()
@ 0x7f4a30769521 google::LogMessageFatal::~LogMessageFatal()
@ 0x7f4a30b8b1ee caffe::ReadNetParamsFromTextFileOrDie()
@ 0x7f4a30b6dfa2 caffe::Solver<>::InitTrainNet()
@ 0x7f4a30b6ee63 caffe::Solver<>::Init()
@ 0x7f4a30b6f036 caffe::Solver<>::Solver()
@ 0x40c3c0 caffe::GetSolver<>()
@ 0x406361 train()
@ 0x4048f1 main
@ 0x7f4a2fe86ec5 (unknown)
@ 0x404e9d (unknown)
Aborted (core dumped)
shaunak@ubuntu:~/caffe$
错误的具体内容是什么,我该如何解决?
更新
这似乎是 运行:
name: "WineNet"
layer {
name: "data"
type: "HDF5Data"
top: "wine_train_data"
top: "wine_train_label"
hdf5_data_param {
source: "examples/wine/train.txt"
batch_size: 10
}
}
layer {
name: "fc1"
type: "InnerProduct"
bottom: "wine_train_data"
top: "fc1"
inner_product_param {
num_output: 2
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "fc1"
bottom: "wine_train_label"
top: "loss"
}
更新2
几乎相同的模型:一个有效,另一个无效。我无法解释为什么!
作品:
name: "WineNet"
layer {
name: "data"
type: "HDF5Data"
top: "wine_train_data"
top: "wine_train_label"
hdf5_data_param {
source: "examples/wine/train.txt"
batch_size: 10
}
}
layer {
name: "fc1"
type: "InnerProduct"
bottom: "wine_train_data"
top: "fc1"
inner_product_param {
num_output: 2
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "fc1"
bottom: "wine_train_label"
top: "loss"
}
不会:
name:"wineclass"
layers {
name: "data"
type: "HDF5Data"
top: "wine_train_data"
top: "wine_train_label"
hdf5_data_param {
source: "examples/wine/train.txt"
batch_size: 10
}
}
layer {
name: "ip"
type: "InnerProduct"
bottom: "wine_train_data"
top: "ip"
inner_product_param {
num_output: 2
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip"
bottom: "wine_train_label"
top: "loss"
}
我运行昨天遇到了同样的问题。您可能需要检查您的 caffe 版本是否是最新的。他们大大改变了 protobuf 的定义。在你的例子中,"type" 曾经是一个枚举,现在它只需要一个字符串。
[更新] 来自评论中的讨论:答案是不用"layers"而是"layer".图层可能存在于一些旧的/过时的示例中。
我正在尝试使用我使用 caffe 库从 CSV 文件准备的 HDF5 数据构建神经网络的最小示例。
我的原文如下:[wine_train.prototxt]
name:"wineclass"
layers {
name: "data"
type: "HDF5Data"
top: "data"
top: "label"
hdf5_data_param {
source: "examples/wine/test.txt"
batch_size: 10
}
include{
phase:TEST
}
}
layer {
name: "data"
type: "HDF5Data"
top: "label"
top: "label"
hdf5_data_param {
source: "examples/wine/train.txt"
batch_size: 2
}
include{
phase:TRAIN
}
}
layers {
name: "ip"
type: "INNER_PRODUCT"
bottom: "data"
top: "ip"
inner_product_param {
num_output: 3
}
}
layers {
name: "loss"
type: "SOFTMAX_LOSS"
bottom: "ip"
bottom: "label"
top: "loss"
}
layer {
name: "accuracy"
type: "Accuracy"
bottom: "ip"
bottom: "label"
top: "accuracy"
include {
phase: TEST
}
}
我的求解器如下:
net: "examples/wine/wine_train.prototxt"
test_iter: 250
test_interval: 1000
base_lr: 0.01
lr_policy: "step"
gamma: 0.1
stepsize: 5000
display: 1000
max_iter: 10000
momentum: 0.9
weight_decay: 0.0005
snapshot: 10000
snapshot_prefix: "wine/train"
solver_mode: CPU
每次我收到以下错误:
shaunak@ubuntu:~/caffe$ build/tools/caffe train -model '/home/shaunak/caffe/examples/wine/wine_train.prototxt' -solver '/home/shaunak/caffe/examples/wine/solver.prototxt'
I0415 04:31:00.154145 57047 caffe.cpp:117] Use CPU.
I0415 04:31:00.154485 57047 caffe.cpp:121] Starting Optimization
I0415 04:31:00.154552 57047 solver.cpp:32] Initializing solver from parameters:
test_iter: 250
test_interval: 1000
base_lr: 0.01
display: 1000
max_iter: 10000
lr_policy: "step"
gamma: 0.1
momentum: 0.9
weight_decay: 0.0005
stepsize: 5000
snapshot: 10000
snapshot_prefix: "wine/train"
solver_mode: CPU
net: "examples/wine/wine_train.prototxt"
I0415 04:31:00.154660 57047 solver.cpp:70] Creating training net from net file: examples/wine/wine_train.prototxt
[libprotobuf ERROR google/protobuf/text_format.cc:245] Error parsing text-format caffe.NetParameter: 4:9: Expected integer or identifier.
F0415 04:31:00.154774 57047 upgrade_proto.cpp:928] Check failed: ReadProtoFromTextFile(param_file, param) Failed to parse NetParameter file: examples/wine/wine_train.prototxt
*** Check failure stack trace: ***
@ 0x7f4a30766c3c google::LogMessage::Fail()
@ 0x7f4a30766b88 google::LogMessage::SendToLog()
@ 0x7f4a3076658a google::LogMessage::Flush()
@ 0x7f4a30769521 google::LogMessageFatal::~LogMessageFatal()
@ 0x7f4a30b8b1ee caffe::ReadNetParamsFromTextFileOrDie()
@ 0x7f4a30b6dfa2 caffe::Solver<>::InitTrainNet()
@ 0x7f4a30b6ee63 caffe::Solver<>::Init()
@ 0x7f4a30b6f036 caffe::Solver<>::Solver()
@ 0x40c3c0 caffe::GetSolver<>()
@ 0x406361 train()
@ 0x4048f1 main
@ 0x7f4a2fe86ec5 (unknown)
@ 0x404e9d (unknown)
Aborted (core dumped)
shaunak@ubuntu:~/caffe$
错误的具体内容是什么,我该如何解决?
更新
这似乎是 运行:
name: "WineNet"
layer {
name: "data"
type: "HDF5Data"
top: "wine_train_data"
top: "wine_train_label"
hdf5_data_param {
source: "examples/wine/train.txt"
batch_size: 10
}
}
layer {
name: "fc1"
type: "InnerProduct"
bottom: "wine_train_data"
top: "fc1"
inner_product_param {
num_output: 2
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "fc1"
bottom: "wine_train_label"
top: "loss"
}
更新2
几乎相同的模型:一个有效,另一个无效。我无法解释为什么!
作品:
name: "WineNet"
layer {
name: "data"
type: "HDF5Data"
top: "wine_train_data"
top: "wine_train_label"
hdf5_data_param {
source: "examples/wine/train.txt"
batch_size: 10
}
}
layer {
name: "fc1"
type: "InnerProduct"
bottom: "wine_train_data"
top: "fc1"
inner_product_param {
num_output: 2
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "fc1"
bottom: "wine_train_label"
top: "loss"
}
不会:
name:"wineclass"
layers {
name: "data"
type: "HDF5Data"
top: "wine_train_data"
top: "wine_train_label"
hdf5_data_param {
source: "examples/wine/train.txt"
batch_size: 10
}
}
layer {
name: "ip"
type: "InnerProduct"
bottom: "wine_train_data"
top: "ip"
inner_product_param {
num_output: 2
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "ip"
bottom: "wine_train_label"
top: "loss"
}
我运行昨天遇到了同样的问题。您可能需要检查您的 caffe 版本是否是最新的。他们大大改变了 protobuf 的定义。在你的例子中,"type" 曾经是一个枚举,现在它只需要一个字符串。
[更新] 来自评论中的讨论:答案是不用"layers"而是"layer".图层可能存在于一些旧的/过时的示例中。