Skip to content

Instantly share code, notes, and snippets.

View Time1ess's full-sized avatar

Youchen Du Time1ess

  • Google
  • Pudong, Shanghai, PRC
View GitHub Profile
@Time1ess
Time1ess / mixins.py
Created January 13, 2018 06:23
DynamicFieldSerializerMixin for DRF
from rest_framework import serializers, exceptions
class DynamicFieldSerializerMixin(serializers.Serializer):
"""
动态指定保留字段
"""
expose_all_possible_fields = True
def __init__(self, *args, **kwargs):
@Time1ess
Time1ess / transforms.py
Created August 5, 2017 11:38
PairRandomCrop is a modified RandomCrop in PyTorch, it supports identical random crop position for both image and target in Semantic Segmentation.
class PairRandomCrop:
"""Crop the given PIL.Image at a random location.
** This is a MODIFIED version **, which supports identical random crop for
both image and target map in Semantic Segmentation.
Args:
size (sequence or int): Desired output size of the crop. If size is an
int instead of sequence like (h, w), a square crop (size, size) is
made.
padding (int or sequence, optional): Optional padding on each border
of the image. Default is 0, i.e no padding. If a sequence of length