utils.py 911 字节
Newer Older
O
overlordmax 已提交
1 2 3 4
import numpy as np 
import os
import paddle.fluid as fluid

O
overlordmax 已提交
5
class Dataset(object):
O
overlordmax 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

    def _reader_creator(self, file):
        def reader():
            with open(file, 'r') as f:
                for i,line in enumerate(f):
                    if i == 0:
                        continue
                    line = line.strip().split(',')
                    features = list(map(float, line))
                    wide_feat = features[0:8]
                    deep_feat = features[8:58+8]
                    label = features[-1]
                    output = []
                    output.append(wide_feat)
                    output.append(deep_feat)
                    output.append([label])
                    
                    yield output

        return reader

    def train(self, file):
        return self._reader_creator(file)

    def test(self, file):
        return self._reader_creator(file)