diff --git a/ppcls/configs/DeepHash/DCH.yaml b/ppcls/configs/DeepHash/DCH.yaml index 2c4df1909d532966edaf7bf2a6af5f5ff97da6e9..bcc2b08e1c87dd9316feda8540b5d2dd5e5fe888 100644 --- a/ppcls/configs/DeepHash/DCH.yaml +++ b/ppcls/configs/DeepHash/DCH.yaml @@ -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 diff --git a/ppcls/configs/DeepHash/DSHSD.yaml b/ppcls/configs/DeepHash/DSHSD.yaml index cd54f61b41ac55f682636fcca6be4dfd05ccc0dc..cf8e8bc1677e95d5289475555ebb6563c76717b2 100644 --- a/ppcls/configs/DeepHash/DSHSD.yaml +++ b/ppcls/configs/DeepHash/DSHSD.yaml @@ -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 diff --git a/ppcls/configs/DeepHash/LCDSH.yaml b/ppcls/configs/DeepHash/LCDSH.yaml index 5130f1b6715afc9cc8b6d5b6998b08204bd9c24b..26600adf4002ff15be454ff7d2d6de42cb8a628c 100644 --- a/ppcls/configs/DeepHash/LCDSH.yaml +++ b/ppcls/configs/DeepHash/LCDSH.yaml @@ -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 diff --git a/ppcls/data/__init__.py b/ppcls/data/__init__.py index 00b74068f2000de2937af34292efdb49ba574b2a..cffac81226d11784b792a56ec774d15f6a5eee54 100644 --- a/ppcls/data/__init__.py +++ b/ppcls/data/__init__.py @@ -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 diff --git a/ppcls/data/dataloader/__init__.py b/ppcls/data/dataloader/__init__.py index acf3f490651cac018e76ac0422aaff19984feaf8..8f81921018634419ba92d77fae92a57112bcdc54 100644 --- a/ppcls/data/dataloader/__init__.py +++ b/ppcls/data/dataloader/__init__.py @@ -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 diff --git a/ppcls/data/dataloader/customized_cifar10.py b/ppcls/data/dataloader/customized_cifar10.py deleted file mode 100644 index 002acee401bc327a516036727269ab9e8c3f9e0f..0000000000000000000000000000000000000000 --- a/ppcls/data/dataloader/customized_cifar10.py +++ /dev/null @@ -1,65 +0,0 @@ -# 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) diff --git a/ppcls/loss/deephashloss.py b/ppcls/loss/deephashloss.py index f58fcc9a65e1ea11668b3bc5c057bb7fe75f0a6c..8230605d7ea7edec9438a4e631335a7fa02dd67c 100644 --- a/ppcls/loss/deephashloss.py +++ b/ppcls/loss/deephashloss.py @@ -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() diff --git a/ppcls/optimizer/optimizer.py b/ppcls/optimizer/optimizer.py index 845da14b05104042be28a8bb777d6a6dc791f1e4..be6fa9f70ab8c50422e8f068b8e1c58a3b1c53e9 100644 --- a/ppcls/optimizer/optimizer.py +++ b/ppcls/optimizer/optimizer.py @@ -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