Skip to content

Instantly share code, notes, and snippets.

@ij96
ij96 / get_tiff_shape.py
Created May 10, 2022 09:21
Get TIFF image shape quickly, by reading the tags rather than the image.
import tifffile
def get_tiff_shape(im_path):
"""
Get TIFF image shape quickly, by reading the tags rather than the image.
"""
with tifffile.TiffFile(im_path) as tif:
c = len(tif.pages)
h = w = None
for tag in tif.pages[0].tags.values():
import numpy as np
def argmax_nd(mat):
return np.unravel_index(mat.argmax(), mat.shape)
@ij96
ij96 / ort_test.py
Last active April 15, 2021 10:08
Code template for infering ONNX model in Python with ONNXRuntime
"""Code template for infering ONNX model in Python with ONNXRuntime"""
import numpy as np
import onnxruntime as ort
import time
onnx_model_path = 'path/to/onnx/model.onnx'
# run the model on the ORT backend
session = ort.InferenceSession(onnx_model_path, None)
def get_number_of_weights(model, trainable_only=True):
if trainable_only:
return sum(p.numel() for p in model.parameters() if p.requires_grad)
return sum(p.numel() for p in model.parameters())
import torch
import torchvision
# for defining networks etc.
import torch.nn as nn
import torch.nn.functional as F
import torchvision.transforms.functional as F_v
# specify torch device
TORCH_DEVICE = 'cuda:0'

Ubuntu Splashtop Streamer reboot issue solution

(Ubuntu 20.04, Splashtop Streamer v2.6.6.0 for Ubuntu)

In the Ubuntu version of Splashtop Streamer, the "Enable auto launch" feature does not work by default. Upon rebooting the computer, the following error occurs:

Fail to connect. Please restart SRStreamer service.

To fix this:

def get_number_of_weights(model):
'''
Calculate the number of weights / params in a Keras model
'''
n_weight = 0
for l in model.layers:
n_weight_layer = 0
for w in l.weights:
n = 1
for i in w.shape:
pip install jupyterthemes
pip install --upgrade jupyterthemes
jt -t onedork -fs 95 -tfs 11 -nfs 115 -cellw 88% -T
@ij96
ij96 / 3d_printer_script.gcode
Last active December 28, 2019 22:27
Custom 3D printing scripts for ideaMaker
;;;;;;;;;; start script
G21 ; set unit to mm
G90 ; set to absolute positioning
M82 ; set extruder to absolute mode
M107 ; fans off
G28 X0 Y0; home X and Y axes
G28 Z0 ; home Z axis
G1 Z15 F300 ; move to (0, 0, 15)
G92 E0 ; set new extruder position to 0
G1 F140 E29 ; extrude 29mm of material
@ij96
ij96 / program_attiny85_via_arduino.md
Created November 17, 2019 19:22
Instruction on how to program ATtiny85 via Arduino

How to: program ATtiny85 via Arduino

Configure Arduino as ISP

  • connect Arduino to the PC.
  • open Arduino IDE.
  • open the ArduinoISP example file (File > Examples > ArduinoISP).
  • note: if using Arduino Mega, modify the following lines from:
#define RESET 10