Skip to content

Instantly share code, notes, and snippets.

#
# Source: https://thepihut.com/blogs/raspberry-pi-tutorials/27968772-turning-on-an-led-with-your-raspberry-pis-gpio-pins
#
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
from time import sleep # Import the sleep function
pinLED = 27 # LED GPIO Pin LED
GPIO.setmode(GPIO.BCM) # Use GPIO pin number
GPIO.setwarnings(False) # Ignore warnings in our case
import argparse
import inspect
import warnings
from typing import List, Optional, Union
from tqdm.auto import tqdm
import torch
from torch import autocast
import numpy as np
def draw_msra_gaussian(heatmap, channel, center, sigma=2):
"""Draw a gaussian on heatmap channel (inplace function).
Args:
heatmap (np.ndarray): heatmap matrix, expected shapes [C, W, H].
channel (int): channel to use for drawing a gaussian.
center (Tuple[int, int]): gaussian center coordinates.
import Jetson.GPIO as GPIO
import time
class Motor:
def __init__(self, ena, in1, in2):
self.ena = ena
self.in1 = in1
self.in2 = in2
import torch
import collections
from typing import List
def checkpoints_weights_avg(inputs: List[str]):
"""Loads checkpoints from inputs and returns a model with averaged weights.
Args:
inputs: An iterable of string paths of checkpoints to load from.
import torch
import torch.nn as nn
from transformers import AutoConfig, AutoModel
class PooledLstmTransfModel(nn.Module):
def __init__(self,
pretrain_dir: str,
num_classes: int = 1):
super(PooledLstmTransfModel, self).__init__()
@ditwoo
ditwoo / f_beta.py
Last active November 10, 2019 21:59
import numpy as np
from numba import njit, prange
@njit(parallel=True)
def _fast_f_beta_score_by_row(y_pred: np.ndarray, y_true: np.ndarray, beta: float) -> float:
num_rows: int = y_true.shape[0]
num_cols: int = y_true.shape[1]
score: float = 0
b2 = beta * beta