Skip to content

Instantly share code, notes, and snippets.

Avatar
🕵️‍♂️
investigating

Marco Forte MarcoForte

🕵️‍♂️
investigating
View GitHub Profile
@MarcoForte
MarcoForte / add_zoom_crop.py
Created Aug 20, 2020
Overlay zoomed in crop on image. Used for creating images in FBA Matting paper.
View add_zoom_crop.py
def add_zoom_crop(img, crop_xs, crop_ys, r, inset_coord):
x1,x2 = crop_xs
y1,y2 = crop_ys
img = (img*255).astype(np.uint8)
inset_coord_end = ( int(inset_coord[0]+(x2-x1)*r), int(inset_coord[1] +(y2-y1)*r))
patch = img[y1:y2,x1:x2]
patch_bigger = cv2.resize(patch, ( int(patch.shape[1]*r), int(patch.shape[0]*r)))
img[inset_coord[1]:inset_coord[1]+patch_bigger.shape[0], inset_coord[0]:inset_coord[0]+patch_bigger.shape[1]] = np.atleast_3d(patch_bigger)
@MarcoForte
MarcoForte / laplacian_loss.py
Created May 6, 2020
laplacian loss used in fba matting
View laplacian_loss.py
########################
# https://gist.github.com/alper111/b9c6d80e2dba1ee0bfac15eb7dad09c8
def gauss_kernel(size=5, device=torch.device('cpu'), channels=3):
kernel = torch.tensor([[1., 4., 6., 4., 1],
[4., 16., 24., 16., 4.],
[6., 24., 36., 24., 6.],
[4., 16., 24., 16., 4.],
View group_weight.py
def group_weight(module, lr_encoder, lr_decoder, WD):
group_decay = { 'encoder': [], 'decoder':[]}
group_bias = { 'encoder': [], 'decoder':[]}
group_GN = { 'encoder': [], 'decoder':[]}
for name, m in module.named_modules():
# if hasattr(m, 'requires_grad'):
# if m.requires_grad:
# continue
@MarcoForte
MarcoForte / colornet.prototxt
Last active Jul 20, 2017
For visualization online
View colornet.prototxt
name: "color"
input: "data"
input_dim: 1
input_dim: 4
input_dim: 256
input_dim: 256
layer {
name: "data_l_ab_mask"
type: "Input"
top: "data_l_ab_mask"
@MarcoForte
MarcoForte / REDNet_ch3.prototxt
Created Jul 5, 2017
Just for quick visualisation with netscope
View REDNet_ch3.prototxt
name: "RED-Net"
input: "data"
input_dim: 1
input_dim: 3
input_dim: 256
input_dim: 256
# conv1
layer {
name: "conv1"
View FactorFactorial
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Primarily about computing factorials"
]
},
{
View Evolution of a Python programmer.py
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
@MarcoForte
MarcoForte / fileDuration.py
Last active Aug 29, 2015
Get audio or video file duration with Powershell through Python on Windows
View fileDuration.py
""" This module shows how to retrieve the duration of an audio or video file on Windows by getting the file details
with Powershell, tested on Powershell 4. """
import subprocess
myFileLocation = r"'C:\Users\Marco\Untitled.wma'" # or myFileLocation = 'C:\\Users\\yourname\\test.mp4'
def getFileDuration(fileLocation):
# Calls the Powershell script that gets the file duration
return subprocess.check_output([r'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe',
'(((New-Object -COMObject Shell.Application).Namespace((Split-Path {0})))).GetDetailsOf((((New-Object -COMObject Shell.Application).Namespace((Split-Path {0}))).ParseName((Split-Path {0} -Leaf))), 183);'.format(myFileLocation)]).decode("utf-8").splitlines()[0]