提交 7ed80c52 编写于 作者: littletomatodonkey's avatar littletomatodonkey

fix program

上级 d609a81d
...@@ -19,7 +19,6 @@ from __future__ import print_function ...@@ -19,7 +19,6 @@ from __future__ import print_function
import numpy as np import numpy as np
import paddle import paddle
from paddle import ParamAttr from paddle import ParamAttr
# from paddle.fluid.param_attr import ParamAttr
import paddle.nn as nn import paddle.nn as nn
from paddle.nn import Conv2d, Pool2D, BatchNorm, Linear, Dropout from paddle.nn import Conv2d, Pool2D, BatchNorm, Linear, Dropout
......
...@@ -18,11 +18,12 @@ from __future__ import print_function ...@@ -18,11 +18,12 @@ from __future__ import print_function
import os import os
import time import time
from collections import OrderedDict from collections import OrderedDict
import paddle import paddle
import paddle.fluid as fluid from paddle import to_tensor
import paddle.nn as nn
import paddle.nn.functional as F
from ppcls.optimizer import LearningRateBuilder from ppcls.optimizer import LearningRateBuilder
from ppcls.optimizer import OptimizerBuilder from ppcls.optimizer import OptimizerBuilder
...@@ -34,8 +35,6 @@ from ppcls.modeling.loss import GoogLeNetLoss ...@@ -34,8 +35,6 @@ from ppcls.modeling.loss import GoogLeNetLoss
from ppcls.utils.misc import AverageMeter from ppcls.utils.misc import AverageMeter
from ppcls.utils import logger from ppcls.utils import logger
from paddle.fluid.dygraph.base import to_variable
def create_dataloader(): def create_dataloader():
""" """
...@@ -45,11 +44,11 @@ def create_dataloader(): ...@@ -45,11 +44,11 @@ def create_dataloader():
feeds(dict): dict of model input variables feeds(dict): dict of model input variables
Returns: Returns:
dataloader(fluid dataloader): dataloader(paddle dataloader):
""" """
trainer_num = int(os.environ.get('PADDLE_TRAINERS_NUM', 1)) trainer_num = int(os.environ.get('PADDLE_TRAINERS_NUM', 1))
capacity = 64 if trainer_num == 1 else 8 capacity = 64 if trainer_num == 1 else 8
dataloader = fluid.io.DataLoader.from_generator( dataloader = paddle.io.DataLoader.from_generator(
capacity=capacity, use_double_buffer=True, iterable=True) capacity=capacity, use_double_buffer=True, iterable=True)
return dataloader return dataloader
...@@ -149,15 +148,15 @@ def create_metric(out, ...@@ -149,15 +148,15 @@ def create_metric(out,
# just need student label to get metrics # just need student label to get metrics
if use_distillation: if use_distillation:
out = out[1] out = out[1]
softmax_out = fluid.layers.softmax(out, use_cudnn=False) softmax_out = F.softmax(out)
fetchs = OrderedDict() fetchs = OrderedDict()
# set top1 to fetchs # set top1 to fetchs
top1 = fluid.layers.accuracy(softmax_out, label=label, k=1) top1 = paddle.metric.accuracy(softmax_out, label=label, k=1)
fetchs['top1'] = top1 fetchs['top1'] = top1
# set topk to fetchs # set topk to fetchs
k = min(topk, classes_num) k = min(topk, classes_num)
topk = fluid.layers.accuracy(softmax_out, label=label, k=k) topk = paddle.metric.accuracy(softmax_out, label=label, k=k)
topk_name = 'top{}'.format(k) topk_name = 'top{}'.format(k)
fetchs[topk_name] = topk fetchs[topk_name] = topk
...@@ -244,12 +243,12 @@ def create_optimizer(config, parameter_list=None): ...@@ -244,12 +243,12 @@ def create_optimizer(config, parameter_list=None):
def create_feeds(batch, use_mix): def create_feeds(batch, use_mix):
image = batch[0] image = batch[0]
if use_mix: if use_mix:
y_a = to_variable(batch[1].numpy().astype("int64").reshape(-1, 1)) y_a = to_tensor(batch[1].numpy().astype("int64").reshape(-1, 1))
y_b = to_variable(batch[2].numpy().astype("int64").reshape(-1, 1)) y_b = to_tensor(batch[2].numpy().astype("int64").reshape(-1, 1))
lam = to_variable(batch[3].numpy().astype("float32").reshape(-1, 1)) lam = to_tensor(batch[3].numpy().astype("float32").reshape(-1, 1))
feeds = {"image": image, "y_a": y_a, "y_b": y_b, "lam": lam} feeds = {"image": image, "y_a": y_a, "y_b": y_b, "lam": lam}
else: else:
label = to_variable(batch[1].numpy().astype('int64').reshape(-1, 1)) label = to_tensor(batch[1].numpy().astype('int64').reshape(-1, 1))
feeds = {"image": image, "label": label} feeds = {"image": image, "label": label}
return feeds return feeds
...@@ -259,7 +258,7 @@ def run(dataloader, config, net, optimizer=None, epoch=0, mode='train'): ...@@ -259,7 +258,7 @@ def run(dataloader, config, net, optimizer=None, epoch=0, mode='train'):
Feed data to the model and fetch the measures and loss Feed data to the model and fetch the measures and loss
Args: Args:
dataloader(fluid dataloader): dataloader(paddle dataloader):
exe(): exe():
program(): program():
fetchs(dict): dict of measures and the loss fetchs(dict): dict of measures and the loss
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册