Tôi đang sử dụng Caffein để phân loại dữ liệu không phải hình ảnh bằng cách sử dụng cấu trúc CNN khá đơn giản. Tôi không gặp vấn đề gì khi đào tạo mạng của mình trên dữ liệu HDF5 với kích thước n x 1 x 156 x 12. Tuy nhiên, tôi đang gặp khó khăn khi phân loại dữ liệu mới.Dự đoán trong Caffein - Ngoại lệ: Các đối số blob đầu vào không khớp với đầu vào mạng
Làm cách nào để chuyển tiếp đơn giản mà không cần xử lý trước? Dữ liệu của tôi đã được chuẩn hóa và có kích thước chính xác cho Caffe (nó đã được sử dụng để đào tạo mạng). Dưới đây là mã của tôi và cấu trúc CNN.
EDIT: tôi đã cô lập các vấn đề với chức năng '_Net_forward' trong pycaffe.py và thấy rằng vấn đề phát sinh như dict self.input trống. Bất cứ ai có thể giải thích lý do tại sao? Tập hợp được cho là bằng với tập hợp đến từ dữ liệu thử nghiệm mới:
if set(kwargs.keys()) != set(self.inputs):
raise Exception('Input blob arguments do not match net inputs.')
Mã của tôi đã thay đổi một chút khi tôi sử dụng phương pháp IO để chuyển dữ liệu thành dữ liệu (xem bên dưới). Theo cách đó tôi đã điền biến kwargs với dữ liệu chính xác.
Ngay cả những gợi ý nhỏ cũng sẽ được đánh giá cao!
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
# Make sure that caffe is on the python path:
caffe_root = '' # this file is expected to be run from {caffe_root}
import sys
sys.path.insert(0, caffe_root + 'python')
import caffe
import os
import subprocess
import h5py
import shutil
import tempfile
import sklearn
import sklearn.datasets
import sklearn.linear_model
import skimage.io
def LoadFromHDF5(dataset='test_reduced.h5', path='Bjarke/hdf5_classification/data/'):
f = h5py.File(path + dataset, 'r')
dat = f['data'][:]
f.close()
return dat;
def runModelPython():
model_file = 'Bjarke/hdf5_classification/conv_v2_simple.prototxt'
pretrained = 'Bjarke/hdf5_classification/data/train_iter_10000.caffemodel'
test_data = LoadFromHDF5()
net = caffe.Net(model_file, pretrained)
caffe.set_mode_cpu()
caffe.set_phase_test()
user = test_data[0,:,:,:]
datum = caffe.io.array_to_datum(user.astype(np.uint8))
user_dat = caffe.io.datum_to_array(datum)
user_dat = user_dat.astype(np.uint8)
out = net.forward_all(data=np.asarray([user_dat]))
if __name__ == '__main__':
runModelPython()
CNN Prototext
name: "CDR-CNN"
layers {
name: "data"
type: HDF5_DATA
top: "data"
top: "label"
hdf5_data_param {
source: "Bjarke/hdf5_classification/data/train.txt"
batch_size: 10
}
include: { phase: TRAIN }
}
layers {
name: "data"
type: HDF5_DATA
top: "data"
top: "label"
hdf5_data_param {
source: "Bjarke/hdf5_classification/data/test.txt"
batch_size: 10
}
include: { phase: TEST }
}
layers {
name: "feature_conv"
type: CONVOLUTION
bottom: "data"
top: "feature_conv"
blobs_lr: 1
blobs_lr: 2
convolution_param {
num_output: 10
kernel_w: 12
kernel_h: 1
stride_w: 1
stride_h: 1
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
}
}
}
layers {
name: "conv1"
type: CONVOLUTION
bottom: "feature_conv"
top: "conv1"
blobs_lr: 1
blobs_lr: 2
convolution_param {
num_output: 14
kernel_w: 1
kernel_h: 4
stride_w: 1
stride_h: 1
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
}
}
}
layers {
name: "pool1"
type: POOLING
bottom: "conv1"
top: "pool1"
pooling_param {
pool: MAX
kernel_w: 1
kernel_h: 3
stride_w: 1
stride_h: 3
}
}
layers {
name: "conv2"
type: CONVOLUTION
bottom: "pool1"
top: "conv2"
blobs_lr: 1
blobs_lr: 2
convolution_param {
num_output: 120
kernel_w: 1
kernel_h: 5
stride_w: 1
stride_h: 1
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
}
}
}
layers {
name: "fc1"
type: INNER_PRODUCT
bottom: "conv2"
top: "fc1"
blobs_lr: 1
blobs_lr: 2
weight_decay: 1
weight_decay: 0
inner_product_param {
num_output: 84
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
}
layers {
name: "accuracy"
type: ACCURACY
bottom: "fc1"
bottom: "label"
top: "accuracy"
include: { phase: TEST }
}
layers {
name: "loss"
type: SOFTMAX_LOSS
bottom: "fc1"
bottom: "label"
top: "loss"
}
Hiển thị lên các tập tin đăng nhập cũng sẽ giúp chúng tôi thu hẹp vấn đề này hơn nữa –
Chỉ cần để cho bạn biết, tôi đã nói với nó không phải là một lỗi trên theo dõi. Tôi đã hỏi cách thực hiện trên danh sách gửi thư nhưng không có câu trả lời cho đến nay https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/caffe-users/eEhSBlKcjpc/llQi9PTPAYsJ – Mark
Cùng vấn đề: https : //groups.google.com/forum/#! topic/caffe-users/aojN_bmbg74 –