Skip to content

Instantly share code, notes, and snippets.

View lantiga's full-sized avatar

Luca Antiga lantiga

View GitHub Profile
# mypy: ignore-errors
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the GNU General Public License version 3.
from typing import Optional, Tuple
from dataclasses import dataclass
import math
import torch
from torch import nn
lantiga /
Last active September 18, 2022 03:03
🤗 Huggingface Bert on RedisAI
from transformers import BertForQuestionAnswering
import torch
bert_name = "bert-large-uncased-whole-word-masking-finetuned-squad"
model = BertForQuestionAnswering.from_pretrained(bert_name, torchscript=True)
inputs = [torch.ones(1, 2, dtype=torch.int64),
torch.ones(1, 2, dtype=torch.int64),
lantiga /
Last active May 6, 2020 16:24
Ultralytics YOLO v3 on RedisAI
# This script saves the ultralytics/yolov3 model to TorchScript
# so that it can be used in RedisAI (or from other C/C++ runtimes)
# git clone
# cd yolov3
# conda create -n pytorch python=3.7
# conda install -yc pytorch pytorch torchvision
# conda install -y numpy opencv
# Copy this script to the root of the repo (yolov3) and run
lantiga /
Last active May 5, 2020 08:23
Build RedisAI with PyTorch backend on NVIDIA Jetson
sudo apt update
sudo apt install -y git build-essential ninja-build cmake python3-pip python3-cffi redis unzip wget
git clone
cd RedisAI
mkdir build
lantiga /
Last active February 6, 2018 23:31
CycleGAN pretrained
import torch
import torch.nn as nn
class ResnetBlock(nn.Module):
def __init__(self, dim):
super(ResnetBlock, self).__init__()
self.conv_block = self.build_conv_block(dim)
lantiga /
Created February 6, 2018 08:25
Indexed convolution

Indexed convolutions

A convolution operator over a 1D tensor (BxCxL), where a list of neighbors for each element is provided through a indices tensor (LxK), where K is the size of the convolution kernel. Each row of indices specifies the indices of the K neighbors of the corresponding element in the input. A -1 is handled like for zero padding.

Note that the neighbors specified in indices are not relative, but rather absolute. They have to be specified for each of the elements of the output.

A use case is for convolutions over non-square lattices, such as images on hexagonal lattices coming from Cherenkov telescopes (


lantiga /
Created September 11, 2017 22:21
PyTorch namespaces tests
import torch
import torch.nn as nn
from torch.autograd import Variable
from graphviz import Digraph
def name(node, annotation=None):
kind = node.kind()
lantiga / vmtk.rb
Created June 10, 2017 14:18
Brew formula for vmtk 1.3.2
class Vmtk < Formula
desc "The Vascular Modeling Toolkit"
homepage ""
url ""
version "1.3.2"
sha256 "2632a74341605bd3ddd97971fad70941329e77a112f9363bc5053a1e2ba7c30e"
head ""
revision 1
# bottle do
### Keybase proof
I hereby claim:
* I am lantiga on github.
* I am lantiga ( on keybase.
* I have a public key whose fingerprint is C364 40F7 E6D0 2B02 AF9C FC34 BE4B 71AA 57A8 4B6A
To claim this, I am signing this object:
lantiga / core.clj
Last active August 29, 2015 14:10
Naive pure rule engine
(ns carla.core
(:require [clojure.math.combinatorics :as combo]))
(defn- fact-matches? [fact match]
(= match (select-keys fact (keys match))))
(defn make-rules [] [])
(defn make-session [] {:facts #{}})