This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Reference | |
| # https://github.com/fuenwang/PanoramaUtility | |
| # https://github.com/fuenwang/Equirec2Perspec | |
| # https://github.com/fuenwang/PanoramaUtility | |
| # https://github.com/timy90022/Perspective-and-Equirectangular | |
| """ | |
| import os | |
| import sys |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # RESTRICT TENSORFLOW TO 2GB OF GPU RAM | |
| # SO THAT WE HAVE 14GB RAM free | |
| LIMIT = 2.0 | |
| gpus = tf.config.experimental.list_physical_devices('GPU') | |
| if gpus: | |
| try: | |
| tf.config.experimental.set_virtual_device_configuration( | |
| gpus[0], | |
| [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=1024*LIMIT)]) | |
| logical_gpus = tf.config.experimental.list_logical_devices('GPU') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class WarmupLearningRateSchedule(optimizers.schedules.LearningRateSchedule): | |
| """WarmupLearningRateSchedule a variety of learning rate | |
| decay schedules with warm up.""" | |
| def __init__( | |
| self, | |
| initial_lr, | |
| steps_per_epoch=None, | |
| lr_decay_type="exponential", | |
| decay_factor=0.97, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RandomGrayscale(layers.Layer): | |
| """Grayscale is a preprocessing layer that transforms | |
| RGB images to Grayscale images. | |
| Input shape: | |
| 3D (unbatched) or 4D (batched) tensor with shape: | |
| `(..., height, width, channels)` format | |
| Output shape: | |
| 3D (unbatched) or 4D (batched) tensor with shape: | |
| `(..., height, width, channels)` format |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def make_plot(tfdata, take_batch=1, title=True, figsize=(20, 20)): | |
| '''ref: https://gist.github.com/innat/4dc4080cfdf5cf20ef0fc93d3623ca9b | |
| ''' | |
| font = { | |
| "family": "serif", | |
| "color": "darkred", | |
| "weight": "normal", | |
| "size": 10, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from functools import partial | |
| import numpy as np | |
| from jax import jit | |
| from jax import random | |
| from jax.experimental import jax2tf | |
| from tensorflow.keras import layers | |
| class RandomChannelShuffle(layers.Layer): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| from tensorflow.keras import layers | |
| class CutMix(layers.Layer): | |
| """Original implementation: https://github.com/keras-team/keras-cv. | |
| The original implementaiton provide more interface to apply mixup on | |
| various CV related task, i.e. object detection etc. It also provides | |
| many effective validation check. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| from tensorflow.keras import layers | |
| class MixUp(layers.Layer): | |
| """Original implementation: https://github.com/keras-team/keras-cv. | |
| The original implementaiton provide more interface to apply mixup on | |
| various CV related task, i.e. object detection etc. It also provides | |
| many effective validation check. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| # https://github.com/tensorflow/tensorflow/issues/55646 | |
| def unique_uniform(num_samples, | |
| minval, | |
| maxval, | |
| seed, | |
| shape, | |
| dtype): # maxval is inclusive |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Case 2: Multiple Class Maks | |
| # String to integer labels. | |
| # Assuming we havae 5 classes like below (excluding background). | |
| categories = { | |
| 'human' : 1, | |
| 'dog' : 2, | |
| 'cat' : 3, | |
| 'bus' : 4, | |
| 'road' : 5 |