Skip to content

Instantly share code, notes, and snippets.

View MarcoForte's full-sized avatar
🕵️‍♂️
investigating

Marco Forte MarcoForte

🕵️‍♂️
investigating
View GitHub Profile
@MarcoForte
MarcoForte / fileDuration.py
Last active August 29, 2015 14:05
Get audio or video file duration with Powershell through Python on Windows
""" 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]
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Primarily about computing factorials"
]
},
{
@MarcoForte
MarcoForte / REDNet_ch3.prototxt
Created July 5, 2017 16:15
Just for quick visualisation with netscope
name: "RED-Net"
input: "data"
input_dim: 1
input_dim: 3
input_dim: 256
input_dim: 256
# conv1
layer {
name: "conv1"
@MarcoForte
MarcoForte / colornet.prototxt
Last active July 20, 2017 20:49
For visualization online
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"
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 / laplacian_loss.py
Created May 6, 2020 21:50
laplacian loss used in fba matting
########################
# 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.],
@MarcoForte
MarcoForte / add_zoom_crop.py
Created August 20, 2020 13:24
Overlay zoomed in crop on image. Used for creating images in FBA Matting paper.
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)