Exemple #1
0
def plot_init():
    """
    绘图初始化函数:
        初始化绘图相关变量
    Args:
    Return:
        cost_ploter -- 用于绘制cost曲线的变量
        error_ploter -- 用于绘制error_rate曲线的变量
    """
    # 绘制cost曲线所做的初始化设置
    cost_ploter = Ploter(train_title_cost, test_title_cost)

    # 绘制error_rate曲线所做的初始化设置
    error_ploter = Ploter(train_title_error, test_title_error)

    ploter = [cost_ploter, error_ploter]

    return ploter
def plot_init():
    """
    绘图初始化函数:
        初始化绘图相关变量
    Args:
    Return:
        cost_ploter -- 用于绘制cost曲线的变量
        error_ploter -- 用于绘制error_rate曲线的变量
    """
    # 绘制cost曲线所做的初始化设置
    cost_ploter = Ploter(TRAIN_TITLE_COST, TEST_TITLE_COST)

    # 绘制error_rate曲线所做的初始化设置
    error_ploter = Ploter(TRAIN_TITLE_ERROR, TEST_TITLE_ERROR)

    ploter = [cost_ploter, error_ploter]

    return ploter
Exemple #3
0
 def test_append(self):
     title1 = "title1"
     title2 = "title2"
     plot_test = Ploter(title1, title2)
     plot_test.append(title1, 1, 2)
     plot_test.append(title1, 2, 5)
     plot_test.append(title2, 3, 4)
     self.assertEqual(plot_test.__plot_data__[title1].step, [1, 2])
     self.assertEqual(plot_test.__plot_data__[title1].value, [2, 5])
     self.assertEqual(plot_test.__plot_data__[title2].step, [3])
     self.assertEqual(plot_test.__plot_data__[title2].value, [4])
     plot_test.reset()
     self.assertEqual(plot_test.__plot_data__[title1].step, [])
     self.assertEqual(plot_test.__plot_data__[title1].value, [])
     self.assertEqual(plot_test.__plot_data__[title2].step, [])
     self.assertEqual(plot_test.__plot_data__[title2].value, [])
Exemple #4
0
#设置测试 reader
test_reader = paddle.batch(
    paddle.reader.shuffle(
        read_data(test_set), buf_size=500),
    batch_size=BATCH_SIZE)

save_dirname="recognize_peech_inference.model"

# 定义回调函数

# Plot data

train_title = "Train cost"
test_title = "Test cost"
plot_cost = Ploter(train_title, test_title)

step = 0
# 事件处理
def event_handler_plot(event):
    global step
    if isinstance(event, fluid.EndStepEvent):
        if event.step % 2 == 0: # 若干个batch,记录cost
            if event.metrics[0] < 10:
                plot_cost.append(train_title, step, event.metrics[0])
                plot_cost.plot()
        if event.step % 20 == 0: # 若干个batch,记录cost
            test_metrics = trainer.test(
                reader=test_reader, feed_order=feed_order)
            if test_metrics[0] < 10:
                plot_cost.append(test_title, step, test_metrics[0])
Exemple #5
0
with_gpu = os.getenv('WITH_GPU', '0') != '0'
paddle.init(use_gpu=with_gpu)

model_member = word2vec.Word2Vec.load("%s/model_member" % MODEL_DIR_TARGET)
model_shop = word2vec.Word2Vec.load("%s/model_shop" % MODEL_DIR_TARGET)

DISTINCT_SHOP = DAO.get_all("review").distinct("shop-id")
CATEGORY_NUM = 36
DISTRICT_NUM = 18
CATEGORICAL_FEATURE_DIMS = [2, 36, 18, 2, 3]
FM_SIZE = len(DISTINCT_SHOP) + sum(CATEGORICAL_FEATURE_DIMS)
EMB_SIZE = 64

title_train = "Train"
title_test = "Test"
ploter = Ploter(title_train, title_test)


def transfer_timestamp(origin_time):
    time_type = type(origin_time)
    if time_type is str or time_type is unicode:
        time_format = "%Y-%m-%d"
        if len(origin_time) > 10:
            time_format = "%Y-%m-%d %H:%M"

        time_tuple = time.strptime(origin_time, time_format)
    elif time_type is datetime.datetime:
        time_tuple = origin_time.timetuple()
    else:
        raise ValueError("Wrong format for time.")
Exemple #6
0
#coding=utf-8
#训练文件
import paddle
import paddle.fluid as fluid
import os
from paddle.v2.plot import Ploter
import numpy as np

train = './data/train.log'
test = './data/test.log'

train_title = "Train cost"
test_title = "Test cost"
cost_ploter = Ploter(train_title, test_title)

global params_dirname
params_dirname = "predict.model"


def train_reader():
    def reader():
        with open(train, 'r') as f:
            lines = [line.strip() for line in f]
            for line in lines:
                line = line.split()
                x = line[0:9]
                y = line[9:11]
                yield x, y

    return reader
Exemple #7
0
import paddle.v2 as paddle
import os
import os.path
import random
from paddle.v2.plot import Ploter

WITH_GPU = os.getenv('WITH_GPU', '0') != '0'
paddle.init(use_gpu=WITH_GPU)

HIDDEN_NUM = [64, 32, 16]

# title_train = "Train"
title_test = "Accurate"
ploter = Ploter(title_test)

is_cla = True


class DataLoader:
    def __init__(self, data_file, float_end, process_num):
        self.file = data_file
        self.float_end = float_end
        self.lines = [l.strip().split(',') for l in open(self.file, 'r')]
        self.train_set = []
        self.test_set = []
        self.split_data(process_num)

    def split_data(self, process_num=0):
        # split_index = len(self.lines) - 15 * process_num - 30
        # self.train_set = self.lines[:split_index]
        # self.test_set = self.lines[split_index: split_index + 30]