Skip to content

Instantly share code, notes, and snippets.

View CharlieCheckpt's full-sized avatar
🎾

CharlieCheckpt

🎾
View GitHub Profile
import torch
import torch.nn as nn
import torch.nn.functional as F
def lengths_to_mask(lengths, max_len=None, dtype=None):
"""
Converts a "lengths" tensor to its binary mask representation.
Based on: https://discuss.pytorch.org/t/how-to-generate-variable-length-mask/23397
@lopspower
lopspower / README.md
Last active May 3, 2024 13:26
Hexadecimal color code for transparency

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

Download This sample on Google Play Store

@Zearin
Zearin / python_decorator_guide.md
Last active March 30, 2024 12:28
The best explanation of Python decorators I’ve ever seen. (An archived answer from StackOverflow.)

NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.


Q: How can I make a chain of function decorators in Python?


If you are not into long explanations, see [Paolo Bergantino’s answer][2].