The most recent use of non-image type data in the training network, I am here to convert this data into a Lmdb type as a data layer and load into the network. The main use of the Caffe Python interface.
1, in the middle tier of the network, it accepts the bottom data of a 1x6 dimension as input;
2, the corresponding 1x6 dimension data of each training sample is stored to data.txt, and the category label is recorded,
3, write Lmdb.
#-*-coding:utf-8-*-Import numpy as NP import Caffe import Lmdb from Caffe.proto import CAFFE_PB2 import Sys,os # Read data and corresponding category tags Theta_file=open ('./data.txt ', ' R ') Label=open ('./label.txt ', ' R ') theta_list=[] In Theta_file:content=line.strip (). Split (', ') theta=[] to I in range (len (content)): Theta.append (Flo At (Content[i]) theta_list.append (theta) del Content,theta theta_file.close () to line in Label:content=l Ine.strip (). Split (' \ n ') theta_label.append (int (content[0)) # Write to Lmdb, you need to convert the list to array db = Lmdb.open (' Data_lmdb ', MAP_ Size=int (1e12)) with Db.begin (write=true) as In_txn:for i in range (len (theta_list)): Datum = Caffe.proto.caff E_pb2.
Datum () Datum.channels = 1 Datum.height = 1 Datum.width = 6 Tmp_=theta_list[i] Tmp=np.array (Range (6), dtype=np.float) for J in Range (6): Tmp[j]=tmp_[j] Label=int (theta_la Bel[i]) datum.data = Tmp.tobytes () # datum.data = tmp.tostring () Datum.label=label in_txn.put (' {: 0>10d} '. for Mat (i), Datum. Serializetostring ()) Db.close ()