提交 efbb0c40 编写于 作者: C chenguowei01

update to 2.0beta

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