Generating Lmdb data of non-image types

Source: Internet
Author: User

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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.