diff --git a/.gitignore b/.gitignore index 7fad702f3a1ccf3a95ef3856b48c22107a536931..4871ce649f83e49648b33fb27d62bf9a179341a2 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ output/ pretrained/ *.ipynb* _build/ +nohup.out diff --git a/ppcls/modeling/architectures/efficientnet.py b/ppcls/modeling/architectures/efficientnet.py index 5952d4c9af833c04b10aeeb8f57fde89310e4242..d6bac79bd8674b6bcb315d512fc095577fc6c97a 100644 --- a/ppcls/modeling/architectures/efficientnet.py +++ b/ppcls/modeling/architectures/efficientnet.py @@ -192,9 +192,9 @@ class EfficientNet(): if is_test: return inputs keep_prob = 1.0 - prob - random_tensor = keep_prob + \ - fluid.layers.uniform_random_batch_size_like( - inputs, [-1, 1, 1, 1], min=0., max=1.) + inputs_shape = fluid.layers.shape(inputs) + random_tensor = keep_prob + fluid.layers.uniform_random( + shape=[inputs_shape[0], 1, 1, 1], min=0., max=1.) binary_tensor = fluid.layers.floor(random_tensor) output = inputs / keep_prob * binary_tensor return output diff --git a/ppcls/modeling/loss.py b/ppcls/modeling/loss.py index 117ac7cc782a5b5cace7796ab3ef6165a36cae86..fde986b5d8ad22f4be3f5b3033adb537157d4324 100644 --- a/ppcls/modeling/loss.py +++ b/ppcls/modeling/loss.py @@ -1,16 +1,16 @@ -#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"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. import paddle.fluid as fluid @@ -34,8 +34,7 @@ class Loss(object): def _labelsmoothing(self, target): if target.shape[-1] != self._class_dim: - one_hot_target = fluid.layers.one_hot( - input=target, depth=self._class_dim) + one_hot_target = fluid.one_hot(input=target, depth=self._class_dim) else: one_hot_target = target soft_target = fluid.layers.label_smooth( diff --git a/ppcls/utils/save_load.py b/ppcls/utils/save_load.py index aed3b88ca69fcb295b6154f66fe6a5df4ca5fec5..e310166ece236cadffa0fc28d3bef6558b4c43e4 100644 --- a/ppcls/utils/save_load.py +++ b/ppcls/utils/save_load.py @@ -1,16 +1,16 @@ # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve. # -#Licensed under the Apache License, Version 2.0 (the "License"); -#you may not use this file except in compliance with the License. -#You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # -#Unless required by applicable law or agreed to in writing, software -#distributed under the License is distributed on an "AS IS" BASIS, -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -#See the License for the specific language governing permissions and -#limitations under the License. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. from __future__ import absolute_import from __future__ import division @@ -18,10 +18,10 @@ from __future__ import print_function import errno import os +import re import shutil import tempfile -import paddle import paddle.fluid as fluid from ppcls.utils import logger @@ -58,7 +58,7 @@ def _load_state(path): 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. Args: @@ -67,7 +67,8 @@ def load_params(exe, prog, path, ignore_params=[]): path (string): URL string or loca model path. ignore_params (list): ignore variable to load when finetuning. 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')): raise ValueError("Model pretrain path {} does not " @@ -101,6 +102,7 @@ def load_params(exe, prog, path, ignore_params=[]): if k in state: logger.warning('variable {} is already excluded automatically'.format(k)) del state[k] + fluid.io.set_program_state(prog, state)