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 STLR(torch.optim.lr_scheduler._LRScheduler): | |
| def __init__(self, optimizer, max_mul, ratio, steps_per_cycle, decay=1, last_epoch=-1): | |
| self.max_mul = max_mul - 1 | |
| self.turning_point = steps_per_cycle // (ratio + 1) | |
| self.steps_per_cycle = steps_per_cycle | |
| self.decay = decay | |
| super().__init__(optimizer, last_epoch) | |
| def get_lr(self): | |
| residual = self.last_epoch % self.steps_per_cycle |
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 ContrastiveLoss(torch.nn.Module): | |
| """ | |
| Contrastive loss function. | |
| Based on: http://yann.lecun.com/exdb/publis/pdf/hadsell-chopra-lecun-06.pdf | |
| """ | |
| def __init__(self, margin=2.0): | |
| super(ContrastiveLoss, self).__init__() | |
| self.margin = margin |
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
| #!/bin/bash | |
| # Based on http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html | |
| # Requires ffmpeg | |
| filename="${1%.*}" | |
| palette="/tmp/palette.png" | |
| filters="scale=320:-1:flags=lanczos" | |
| ffmpeg -v warning -i "$1" -vf "$filters,palettegen" -y $palette | |
| ffmpeg -v warning -i "$1" -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y "$filename.gif" |
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 shapefile | |
| # read the shapefile | |
| reader = shapefile.Reader("my.shp") | |
| fields = reader.fields[1:] | |
| field_names = [field[0] for field in fields] | |
| buffer = [] | |
| for sr in reader.shapeRecords(): | |
| atr = dict(zip(field_names, sr.record)) | |
| geom = sr.shape.__geo_interface__ | |
| buffer.append(dict(type="Feature", \ |