提交 509f4d77 编写于 作者: L lubin

modify the cifar10 dataset format

上级 cef3cb25
......@@ -62,8 +62,20 @@ Optimizer:
DataLoader:
Train:
dataset:
name: CustomizedCifar10
mode: 'train'
name: ImageNetDataset
image_root: ./dataset/
cls_label_path: ./dataset/cifar10-2/train.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
size: 224
- NormalizeImage:
scale: 1.0/255.0
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
order: ''
sampler:
batch_size: 128
drop_last: False
......@@ -74,9 +86,21 @@ DataLoader:
Eval:
Query:
dataset:
name: CustomizedCifar10
mode: 'test'
dataset:
name: ImageNetDataset
image_root: ./dataset/
cls_label_path: ./dataset/cifar10-2/test.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
size: 224
- NormalizeImage:
scale: 1.0/255.0
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
order: ''
sampler:
batch_size: 128
drop_last: False
......@@ -86,9 +110,21 @@ DataLoader:
use_shared_memory: True
Gallery:
dataset:
name: CustomizedCifar10
mode: 'train'
dataset:
name: ImageNetDataset
image_root: ./dataset/
cls_label_path: ./dataset/cifar10-2/database.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
size: 224
- NormalizeImage:
scale: 1.0/255.0
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
order: ''
sampler:
batch_size: 128
drop_last: False
......
......@@ -63,8 +63,20 @@ Optimizer:
DataLoader:
Train:
dataset:
name: CustomizedCifar10
mode: 'train'
name: ImageNetDataset
image_root: ./dataset/
cls_label_path: ./dataset/cifar10-2/train.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
size: 224
- NormalizeImage:
scale: 1.0/255.0
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
order: ''
sampler:
batch_size: 128
drop_last: False
......@@ -75,9 +87,21 @@ DataLoader:
Eval:
Query:
dataset:
name: CustomizedCifar10
mode: 'test'
dataset:
name: ImageNetDataset
image_root: ./dataset/
cls_label_path: ./dataset/cifar10-2/test.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
size: 224
- NormalizeImage:
scale: 1.0/255.0
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
order: ''
sampler:
batch_size: 128
drop_last: False
......@@ -87,9 +111,21 @@ DataLoader:
use_shared_memory: True
Gallery:
dataset:
name: CustomizedCifar10
mode: 'train'
dataset:
name: ImageNetDataset
image_root: ./dataset/
cls_label_path: ./dataset/cifar10-2/database.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
size: 224
- NormalizeImage:
scale: 1.0/255.0
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
order: ''
sampler:
batch_size: 128
drop_last: False
......
......@@ -59,8 +59,20 @@ Optimizer:
DataLoader:
Train:
dataset:
name: CustomizedCifar10
mode: 'train'
name: ImageNetDataset
image_root: ./dataset/
cls_label_path: ./dataset/cifar10-2/train.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
size: 224
- NormalizeImage:
scale: 1.0/255.0
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
order: ''
sampler:
batch_size: 128
drop_last: False
......@@ -71,9 +83,21 @@ DataLoader:
Eval:
Query:
dataset:
name: CustomizedCifar10
mode: 'test'
dataset:
name: ImageNetDataset
image_root: ./dataset/
cls_label_path: ./dataset/cifar10-2/test.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
size: 224
- NormalizeImage:
scale: 1.0/255.0
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
order: ''
sampler:
batch_size: 128
drop_last: False
......@@ -83,9 +107,21 @@ DataLoader:
use_shared_memory: True
Gallery:
dataset:
name: CustomizedCifar10
mode: 'train'
dataset:
name: ImageNetDataset
image_root: ./dataset/
cls_label_path: ./dataset/cifar10-2/database.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
size: 224
- NormalizeImage:
scale: 1.0/255.0
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
order: ''
sampler:
batch_size: 128
drop_last: False
......
......@@ -28,7 +28,6 @@ from ppcls.data.dataloader.vehicle_dataset import CompCars, VeriWild
from ppcls.data.dataloader.logo_dataset import LogoDataset
from ppcls.data.dataloader.icartoon_dataset import ICartoonDataset
from ppcls.data.dataloader.mix_dataset import MixDataset
from ppcls.data.dataloader.customized_cifar10 import CustomizedCifar10
# sampler
from ppcls.data.dataloader.DistributedRandomIdentitySampler import DistributedRandomIdentitySampler
......
......@@ -4,7 +4,6 @@ from ppcls.data.dataloader.common_dataset import create_operators
from ppcls.data.dataloader.vehicle_dataset import CompCars, VeriWild
from ppcls.data.dataloader.logo_dataset import LogoDataset
from ppcls.data.dataloader.icartoon_dataset import ICartoonDataset
from ppcls.data.dataloader.customized_cifar10 import CustomizedCifar10
from ppcls.data.dataloader.mix_dataset import MixDataset
from ppcls.data.dataloader.mix_sampler import MixSampler
from ppcls.data.dataloader.pk_sampler import PKSampler
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# 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.
import paddle
from paddle.vision.datasets import Cifar10
from paddle.vision import transforms
from paddle.dataset.common import _check_exists_and_download
import numpy as np
import os
from PIL import Image
class CustomizedCifar10(Cifar10):
def __init__(self,
data_file=None,
mode='train',
download=True,
backend=None):
assert mode.lower() in ['train', 'test'], \
"mode should be 'train', 'test', but got {}".format(mode)
self.mode = mode.lower()
if backend is None:
backend = paddle.vision.get_image_backend()
if backend not in ['pil', 'cv2']:
raise ValueError(
"Expected backend are one of ['pil', 'cv2'], but got {}"
.format(backend))
self.backend = backend
self._init_url_md5_flag()
self.data_file = data_file
if self.data_file is None:
assert download, "data_file is not set and downloading automatically is disabled"
self.data_file = _check_exists_and_download(
data_file, self.data_url, self.data_md5, 'cifar', download)
self.transform = transforms.Compose([
transforms.Resize(224), transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
self._load_data()
self.dtype = paddle.get_default_dtype()
def __getitem__(self, index):
img, target = self.data[index]
img = np.reshape(img, [3, 32, 32])
img = img.transpose([1, 2, 0]).astype("uint8")
img = Image.fromarray(img)
img = self.transform(img)
return (img, target)
......@@ -132,7 +132,7 @@ class DCHLoss(paddle.nn.Layer):
paddle.log(1 + self.gamma / d_hi_hj))
all_one = paddle.ones_like(u, dtype="float32")
quantization_loss = paddle.log(1 + self.d(u.abs(), all_one) /
quantization_loss = paddle.log(1 + self.distance(u.abs(), all_one) /
self.gamma)
loss = cauchy_loss.mean() + self._lambda * quantization_loss.mean()
......
......@@ -49,13 +49,11 @@ class SGD(object):
learning_rate=0.001,
weight_decay=None,
grad_clip=None,
name=None,
multi_precision=False):
name=None):
self.learning_rate = learning_rate
self.weight_decay = weight_decay
self.grad_clip = grad_clip
self.name = name
self.multi_precision = multi_precision
def __call__(self, model_list):
# model_list is None in static graph
......@@ -65,8 +63,7 @@ class SGD(object):
parameters=parameters,
weight_decay=self.weight_decay,
grad_clip=self.grad_clip,
name=self.name,
multi_precision=self.multi_precision)
name=self.name)
return opt
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册