karolmajek/maxdeeplab
0
1# coding=utf-82# Copyright 2021 The Deeplab2 Authors.3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15 16"""AutoAugment policy file.17 18This file contains found auto-augment policy.19 20Please cite or refer to the following papers for details:21- Ekin D Cubuk, Barret Zoph, Dandelion Mane, Vijay Vasudevan, and Quoc V Le.22"Autoaugment: Learning augmentation policies from data." In CVPR, 2019.23 24- Ekin D Cubuk, Barret Zoph, Jonathon Shlens, and Quoc V Le.25"Randaugment: Practical automated data augmentation with a reduced search26space." In CVPR, 2020.27"""28 29# Reduced augmentation operation space.30augmentation_reduced_operations = (31 'AutoContrast', 'Equalize', 'Invert', 'Posterize',32 'Solarize', 'Color', 'Contrast', 'Brightness', 'Sharpness')33 34augmentation_probabilities = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0]35 36 37def convert_policy(policy,38 search_space=augmentation_reduced_operations,39 probability_scale=1.0,40 magnitude_scale=1):41 """Converts policy from a list of numbers."""42 if len(policy) % 6:43 raise ValueError('Policy length must be a multiple of 6.')44 num_policies = len(policy) // 645 policy_list = [[] for _ in range(num_policies)]46 for n in range(num_policies):47 for i in range(2):48 operation_id, prob_id, magnitude = (49 policy[6 * n + i * 3 : 6 * n + (i + 1) * 3])50 policy_name = search_space[operation_id]51 policy_prob = (52 augmentation_probabilities[prob_id] * probability_scale)53 policy_list[n].append((policy_name,54 policy_prob,55 magnitude * magnitude_scale))56 return policy_list57 58 59simple_classification_policy = [8, 2, 7, 7, 1, 10,60 1, 0, 9, 6, 1, 10,61 8, 1, 9, 5, 1, 9,62 4, 1, 7, 1, 3, 9,63 8, 1, 1, 1, 1, 7]64 65# All available policies.66available_policies = {67 'simple_classification_policy_magnitude_scale_0.2': convert_policy(68 simple_classification_policy,69 augmentation_reduced_operations,70 magnitude_scale=0.2),71 'simple_classification_policy': convert_policy(72 simple_classification_policy,73 augmentation_reduced_operations,74 magnitude_scale=1),75}76 