Skip to content

Instantly share code, notes, and snippets.

def trimmed_mae_loss(prediction, target, mask, trim=0.2):
M = torch.sum(mask, (1, 2))
res = prediction - target
res = res[mask.bool()].abs()
trimmed, _ = torch.sort(res.view(-1), descending=False)[
: int(len(res) * (1.0 - trim))
]
@dvdhfnr
dvdhfnr / midas_loss.py
Last active June 25, 2024 23:49
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))
@jamietre
jamietre / transcodemvc.bat
Last active September 16, 2023 01:14
Batch file for transcoding MVC 3D streams in an MKV container
@ECHO OFF
rem usage: transcodemvc input output [-r] [-s]
rem -r will re-use a previously extracted elementary stream from the temp file location
rem -s will swap eyes
set TEMP_DIR=c:\temp\recodemvc
set TEMP_FILE=%TEMP_DIR%\temp_mvc.264
set PROFILE=high
set SWAP=false