未验证 提交 f14b3f30 编写于 作者: D dyning 提交者: GitHub

Merge pull request #118 from WuHaobo/master

update some api to support paddle1.8
...@@ -8,3 +8,4 @@ output/ ...@@ -8,3 +8,4 @@ output/
pretrained/ pretrained/
*.ipynb* *.ipynb*
_build/ _build/
nohup.out
...@@ -192,9 +192,9 @@ class EfficientNet(): ...@@ -192,9 +192,9 @@ class EfficientNet():
if is_test: if is_test:
return inputs return inputs
keep_prob = 1.0 - prob keep_prob = 1.0 - prob
random_tensor = keep_prob + \ inputs_shape = fluid.layers.shape(inputs)
fluid.layers.uniform_random_batch_size_like( random_tensor = keep_prob + fluid.layers.uniform_random(
inputs, [-1, 1, 1, 1], min=0., max=1.) shape=[inputs_shape[0], 1, 1, 1], min=0., max=1.)
binary_tensor = fluid.layers.floor(random_tensor) binary_tensor = fluid.layers.floor(random_tensor)
output = inputs / keep_prob * binary_tensor output = inputs / keep_prob * binary_tensor
return output return output
......
#copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
# #
#Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
#You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
#Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
#limitations under the License. # limitations under the License.
import paddle.fluid as fluid import paddle.fluid as fluid
...@@ -34,8 +34,7 @@ class Loss(object): ...@@ -34,8 +34,7 @@ class Loss(object):
def _labelsmoothing(self, target): def _labelsmoothing(self, target):
if target.shape[-1] != self._class_dim: if target.shape[-1] != self._class_dim:
one_hot_target = fluid.layers.one_hot( one_hot_target = fluid.one_hot(input=target, depth=self._class_dim)
input=target, depth=self._class_dim)
else: else:
one_hot_target = target one_hot_target = target
soft_target = fluid.layers.label_smooth( soft_target = fluid.layers.label_smooth(
......
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
# #
#Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
#You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
#Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
#limitations under the License. # limitations under the License.
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import division from __future__ import division
...@@ -18,10 +18,10 @@ from __future__ import print_function ...@@ -18,10 +18,10 @@ from __future__ import print_function
import errno import errno
import os import os
import re
import shutil import shutil
import tempfile import tempfile
import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
from ppcls.utils import logger from ppcls.utils import logger
...@@ -58,7 +58,7 @@ def _load_state(path): ...@@ -58,7 +58,7 @@ def _load_state(path):
return state return state
def load_params(exe, prog, path, ignore_params=[]): def load_params(exe, prog, path, ignore_params=None):
""" """
Load model from the given path. Load model from the given path.
Args: Args:
...@@ -67,7 +67,8 @@ def load_params(exe, prog, path, ignore_params=[]): ...@@ -67,7 +67,8 @@ def load_params(exe, prog, path, ignore_params=[]):
path (string): URL string or loca model path. path (string): URL string or loca model path.
ignore_params (list): ignore variable to load when finetuning. ignore_params (list): ignore variable to load when finetuning.
It can be specified by finetune_exclude_pretrained_params It can be specified by finetune_exclude_pretrained_params
and the usage can refer to docs/advanced_tutorials/TRANSFER_LEARNING.md and the usage can refer to the document
docs/advanced_tutorials/TRANSFER_LEARNING.md
""" """
if not (os.path.isdir(path) or os.path.exists(path + '.pdparams')): if not (os.path.isdir(path) or os.path.exists(path + '.pdparams')):
raise ValueError("Model pretrain path {} does not " raise ValueError("Model pretrain path {} does not "
...@@ -101,6 +102,7 @@ def load_params(exe, prog, path, ignore_params=[]): ...@@ -101,6 +102,7 @@ def load_params(exe, prog, path, ignore_params=[]):
if k in state: if k in state:
logger.warning('variable {} is already excluded automatically'.format(k)) logger.warning('variable {} is already excluded automatically'.format(k))
del state[k] del state[k]
fluid.io.set_program_state(prog, state) fluid.io.set_program_state(prog, state)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册