提交 efbb0c40 编写于 作者: C chenguowei01

update to 2.0beta

上级 3fa39034
...@@ -17,10 +17,9 @@ import os ...@@ -17,10 +17,9 @@ import os
import numpy as np import numpy as np
import tqdm import tqdm
import cv2 import cv2
from paddle.fluid.dygraph.base import to_variable
import paddle.fluid as fluid
import paddle.nn.functional as F
import paddle import paddle
import paddle.nn.functional as F
from paddle import to_variable
import paddleseg.utils.logger as logger import paddleseg.utils.logger as logger
from paddleseg.utils import ConfusionMatrix from paddleseg.utils import ConfusionMatrix
...@@ -34,7 +33,7 @@ def evaluate(model, ...@@ -34,7 +33,7 @@ def evaluate(model,
ignore_index=255, ignore_index=255,
iter_id=None): iter_id=None):
ckpt_path = os.path.join(model_dir, 'model') ckpt_path = os.path.join(model_dir, 'model')
para_state_dict, opti_state_dict = fluid.load_dygraph(ckpt_path) para_state_dict, opti_state_dict = paddle.load(ckpt_path)
model.set_dict(para_state_dict) model.set_dict(para_state_dict)
model.eval() model.eval()
......
...@@ -12,19 +12,19 @@ ...@@ -12,19 +12,19 @@
# 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.nn as nn
def constant_init(param, **kwargs): def constant_init(param, **kwargs):
initializer = fluid.initializer.Constant(**kwargs) initializer = nn.initializer.Constant(**kwargs)
initializer(param, param.block) initializer(param, param.block)
def normal_init(param, **kwargs): def normal_init(param, **kwargs):
initializer = fluid.initializer.Normal(**kwargs) initializer = nn.initializer.Normal(**kwargs)
initializer(param, param.block) initializer(param, param.block)
def msra_init(param, **kwargs): def msra_init(param, **kwargs):
initializer = fluid.initializer.MSRA(**kwargs) initializer = nn.initializer.MSRA(**kwargs)
initializer(param, param.block) initializer(param, param.block)
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
import os import os
import paddle.fluid as fluid import paddle
import numpy as np import numpy as np
from PIL import Image from PIL import Image
...@@ -23,7 +23,7 @@ from paddleseg.transforms import Compose ...@@ -23,7 +23,7 @@ from paddleseg.transforms import Compose
@manager.DATASETS.add_component @manager.DATASETS.add_component
class Dataset(fluid.io.Dataset): class Dataset(paddle.io.Dataset):
"""Pass in a custom dataset that conforms to the format. """Pass in a custom dataset that conforms to the format.
Args: Args:
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
import paddle import paddle
from paddle import nn from paddle import nn
import paddle.nn.functional as F import paddle.nn.functional as F
import paddle.fluid as fluid
from paddleseg.cvlibs import manager from paddleseg.cvlibs import manager
''' '''
...@@ -107,34 +106,15 @@ class CrossEntropyLoss(nn.Layer): ...@@ -107,34 +106,15 @@ class CrossEntropyLoss(nn.Layer):
if len(label.shape) != len(logit.shape): if len(label.shape) != len(logit.shape):
label = paddle.unsqueeze(label, 1) label = paddle.unsqueeze(label, 1)
# logit = paddle.transpose(logit, [0, 2, 3, 1]) logit = paddle.transpose(logit, [0, 2, 3, 1])
# label = paddle.transpose(label, [0, 2, 3, 1]) label = paddle.transpose(label, [0, 2, 3, 1])
# loss = F.softmax_with_cross_entropy( loss = F.softmax_with_cross_entropy(
# logit, label, ignore_index=self.ignore_index, axis=-1) logit, label, ignore_index=self.ignore_index, axis=-1)
# loss = paddle.reduce_mean(loss)
# mask = label != self.ignore_index
# mask = paddle.cast(mask, 'float32')
# avg_loss = loss / (paddle.mean(mask) + self.EPS)
# label.stop_gradient = True
# mask.stop_gradient = True
# return avg_loss
logit = fluid.layers.transpose(logit, [0, 2, 3, 1])
label = fluid.layers.transpose(label, [0, 2, 3, 1])
mask = label != self.ignore_index mask = label != self.ignore_index
mask = fluid.layers.cast(mask, 'float32') mask = paddle.cast(mask, 'float32')
loss, probs = fluid.layers.softmax_with_cross_entropy(
logit,
label,
ignore_index=self.ignore_index,
return_softmax=True,
axis=-1)
loss = loss * mask loss = loss * mask
avg_loss = fluid.layers.mean(loss) / ( avg_loss = paddle.reduce_mean(loss) / (paddle.mean(mask) + self.EPS)
fluid.layers.mean(mask) + self.EPS)
label.stop_gradient = True label.stop_gradient = True
mask.stop_gradient = True mask.stop_gradient = True
......
...@@ -19,8 +19,8 @@ import subprocess ...@@ -19,8 +19,8 @@ import subprocess
import glob import glob
import paddle import paddle
import paddle.fluid as fluid
import cv2 import cv2
from paddle.distributed import ParallelEnv
IS_WINDOWS = sys.platform == 'win32' IS_WINDOWS = sys.platform == 'win32'
...@@ -96,13 +96,14 @@ def get_environ_info(): ...@@ -96,13 +96,14 @@ def get_environ_info():
env_info['Python'] = sys.version.replace('\n', '') env_info['Python'] = sys.version.replace('\n', '')
# todo is_compiled_with_cuda() has not been moved
compiled_with_cuda = paddle.fluid.is_compiled_with_cuda() compiled_with_cuda = paddle.fluid.is_compiled_with_cuda()
env_info['Paddle compiled with cuda'] = compiled_with_cuda env_info['Paddle compiled with cuda'] = compiled_with_cuda
if compiled_with_cuda: if compiled_with_cuda:
cuda_home = _find_cuda_home() cuda_home = _find_cuda_home()
env_info['NVCC'] = _get_nvcc_info(cuda_home) env_info['NVCC'] = _get_nvcc_info(cuda_home)
gpu_nums = fluid.core.get_cuda_device_count() gpu_nums = ParallelEnv().nranks
env_info['GPUs used'] = gpu_nums env_info['GPUs used'] = gpu_nums
env_info['CUDA_VISIBLE_DEVICES'] = os.environ.get( env_info['CUDA_VISIBLE_DEVICES'] = os.environ.get(
'CUDA_VISIBLE_DEVICES') 'CUDA_VISIBLE_DEVICES')
......
...@@ -16,7 +16,7 @@ import time ...@@ -16,7 +16,7 @@ import time
import os import os
import sys import sys
from paddle.fluid.dygraph.parallel import ParallelEnv from paddle.distributed import ParallelEnv
levels = {0: 'ERROR', 1: 'WARNING', 2: 'INFO', 3: 'DEBUG'} levels = {0: 'ERROR', 1: 'WARNING', 2: 'INFO', 3: 'DEBUG'}
log_level = 2 log_level = 2
......
...@@ -14,11 +14,12 @@ ...@@ -14,11 +14,12 @@
import contextlib import contextlib
import os import os
import numpy as np
import math import math
import numpy as np
import cv2 import cv2
import tempfile import tempfile
import paddle.fluid as fluid import paddle
from urllib.parse import urlparse, unquote from urllib.parse import urlparse, unquote
import filelock import filelock
...@@ -74,10 +75,7 @@ def load_pretrained_model(model, pretrained_model): ...@@ -74,10 +75,7 @@ def load_pretrained_model(model, pretrained_model):
if os.path.exists(pretrained_model): if os.path.exists(pretrained_model):
ckpt_path = os.path.join(pretrained_model, 'model') ckpt_path = os.path.join(pretrained_model, 'model')
try: para_state_dict, _ = paddle.load(ckpt_path)
para_state_dict, _ = fluid.load_dygraph(ckpt_path)
except:
para_state_dict = fluid.load_program_state(pretrained_model)
model_state_dict = model.state_dict() model_state_dict = model.state_dict()
keys = model_state_dict.keys() keys = model_state_dict.keys()
...@@ -115,7 +113,7 @@ def resume(model, optimizer, resume_model): ...@@ -115,7 +113,7 @@ def resume(model, optimizer, resume_model):
if os.path.exists(resume_model): if os.path.exists(resume_model):
resume_model = os.path.normpath(resume_model) resume_model = os.path.normpath(resume_model)
ckpt_path = os.path.join(resume_model, 'model') ckpt_path = os.path.join(resume_model, 'model')
para_state_dict, opti_state_dict = fluid.load_dygraph(ckpt_path) para_state_dict, opti_state_dict = paddle.load(ckpt_path)
model.set_dict(para_state_dict) model.set_dict(para_state_dict)
optimizer.set_dict(opti_state_dict) optimizer.set_dict(opti_state_dict)
epoch = resume_model.split('_')[-1] epoch = resume_model.split('_')[-1]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册