Skip to content

Instantly share code, notes, and snippets.

View ionvision's full-sized avatar
🎯
Focusing

Xuejian Rong ionvision

🎯
Focusing
View GitHub Profile
@ionvision
ionvision / writeVideoFromImages.py
Created June 25, 2021 08:02 — forked from laygond/writeVideoFromImages.py
Write Video from Images using MoviePy and OpenCV
#pip3 install -U imageio-ffmpeg # It contains VideoFileClip module and must be installed from shell
#from moviepy.editor import VideoFileClip,ImageSequenceClip # Must be added in the beginning with the rest of imported modules
# Define Input and Output folder (USER must Edit)
video_name = "sample.mp4"
video_name_part = video_name.split(".") # sample & mp4 has been split
input_video_path = os.path.join("Input_Video", video_name)
output_images_path = os.path.join("Output_Video", "Processed_Images") # This is a temporary folder to hold processed images
output_video_path = os.path.join("Output_Video", video_name_part[0] + "_output." + video_name_part[1])
@ionvision
ionvision / midas_loss.py
Created August 26, 2020 04:23 — 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))
@ionvision
ionvision / ffmpeg_mkv_mp4_conversion.md
Created June 3, 2020 04:18 — forked from jamesmacwhite/ffmpeg_mkv_mp4_conversion.md
Easy way to convert MKV to MP4 with ffmpeg

Converting mkv to mp4 with ffmpeg

Essentially just copy the existing video and audio stream as is into a new container, no funny business!

The easiest way to "convert" MKV to MP4, is to copy the existing video and audio streams and place them into a new container. This avoids any encoding task and hence no quality will be lost, it is also a fairly quick process and requires very little CPU power. The main factor is disk read/write speed.

With ffmpeg this can be achieved with -c copy. Older examples may use -vcodec copy -acodec copy which does the same thing.

These examples assume ffmpeg is in your PATH. If not just substitute with the full path to your ffmpeg binary.

Single file conversion example

@ionvision
ionvision / hook_activations.py
Created August 5, 2019 07:55 — forked from Tushar-N/hook_activations.py
Pytorch code to save activations for specific layers over an entire dataset
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision.models as tmodels
from functools import partial
import collections
# dummy data: 10 batches of images with batch size 16
dataset = [torch.rand(16,3,224,224).cuda() for _ in range(10)]
#eee5f8 #eee5f8 #c9c0d3 #c9c0d3 #c7b8a1 #c7b8a1 #faead3 #faead3 #ead0d1 #ead0d1 #a27e7e #a27e7e
#7a7281 #7a7281 #a6a6a8 #a6a6a8 #cac3bb #cac3bb ![#f0ebe5](https:

FWIW: I didn't produce the content presented here (the outline from Edmond Lau's book). I've just copy-pasted it from somewhere over the Internet, but I cannot remember what exactly the original source is. I was also not able to find the author's name, so I cannot give him/her the proper credits.


Effective Engineer - Notes

What's an Effective Engineer?

@ionvision
ionvision / parallel.py
Created October 29, 2018 19:42 — forked from thomwolf/parallel.py
Data Parallelism in PyTorch for modules and losses
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
## Created by: Hang Zhang, Rutgers University, Email: zhang.hang@rutgers.edu
## Modified by Thomas Wolf, HuggingFace Inc., Email: thomas@huggingface.co
## Copyright (c) 2017-2018
##
## This source code is licensed under the MIT-style license found in the
## LICENSE file in the root directory of this source tree
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
"""Encoding Data Parallel"""
@ionvision
ionvision / iterm2-solarized.md
Created May 7, 2018 21:48 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Meslo powerline font + [Powerlevel9k] - (macOS)

Default

Default

Powerlevel9k

Powerlevel9k

@ionvision
ionvision / imagenet1000_clsid_to_human.txt
Created April 27, 2018 13:08 — forked from yrevar/imagenet1000_clsidx_to_labels.txt
text: imagenet 1000 class id to human readable labels (Fox, E., & Guestrin, C. (n.d.). Coursera Machine Learning Specialization.)
{0: 'tench, Tinca tinca',
1: 'goldfish, Carassius auratus',
2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias',
3: 'tiger shark, Galeocerdo cuvieri',
4: 'hammerhead, hammerhead shark',
5: 'electric ray, crampfish, numbfish, torpedo',
6: 'stingray',
7: 'cock',
8: 'hen',
9: 'ostrich, Struthio camelus',
{"lastUpload":"2019-05-02T11:02:57.132Z","extensionVersion":"v3.2.9"}