Skip to content

Instantly share code, notes, and snippets.

View marcelsan's full-sized avatar
💭
I may be slow to respond.

Marcel Santana marcelsan

💭
I may be slow to respond.
View GitHub Profile
@marcelsan
marcelsan / midas_loss.py
Created October 9, 2020 14:40 — forked from dvdhfnr/midas_loss.py
Loss function of MiDaS
import torch
import torch.nn as nn
def compute_scale_and_shift(prediction, target, mask):
# system matrix: A = [[a_00, a_01], [a_10, a_11]]
a_00 = torch.sum(mask * prediction * prediction, (1, 2))
a_01 = torch.sum(mask * prediction, (1, 2))
a_11 = torch.sum(mask, (1, 2))
@marcelsan
marcelsan / vgg.py
Created February 5, 2019 15:23
This script will demonstrate how to use a pretrained model, in PyTorch, to make predictions.
"""
This script will demonstrate how to use a pretrained model, in PyTorch,
to make predictions. Specifically, we will be using VGG16 with a cat
image.
References used to make this script:
PyTorch pretrained models doc:
http://pytorch.org/docs/master/torchvision/models.html
PyTorch image transforms example:
http://pytorch.org/tutorials/beginner/data_loading_tutorial.html#transforms
import numpy as np
class KernelDensity:
def __init__(self, kernel='gaussian', bandwidth=0.2):
self.kernel_ = kernel
self.bandwidth_ = bandwidth
def fit(self, X):
self.X_ = X
self.n_ = X.shape[0]
@marcelsan
marcelsan / disp_multiple_images.py
Created March 15, 2018 19:35 — forked from soply/disp_multiple_images.py
Plot multiple images with matplotlib in a single figure. Titles can be given optionally as second argument.
import matplotlib.pyplot as plt
import numpy as np
def show_images(images, cols = 1, titles = None):
"""Display a list of images in a single figure with matplotlib.
Parameters
---------
images: List of np.arrays compatible with plt.imshow.
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt
from sklearn import datasets
iris = datasets.load_iris()
X = iris.data
model = PCA()
model.fit(X)
@marcelsan
marcelsan / jupyter.sh
Created December 26, 2017 17:31 — forked from Colelyman/jupyter.sh
Get Jupyter Notebook Running in SSH Tunnel
user@server$ jupyter notebook --no-browser --port=8889
# run client side
user@client$ ssh -N -f -L localhost:8000:localhost:8889 remote_user@remote_host
firefox http://localhost:8000
# source: https://coderwall.com/p/ohk6cg/remote-access-to-ipython-notebooks-via-ssh
@marcelsan
marcelsan / Range.hpp
Created November 8, 2017 17:31 — forked from tunabrain/Range.hpp
Python ranges in C++
#ifndef RANGE_HPP_
#define RANGE_HPP_
template<typename T> class RangeIterator;
template<typename T>
class Range
{
T _start, _end, _step;