Skip to content

Instantly share code, notes, and snippets.

pip install jupyterthemes
pip install --upgrade jupyterthemes
jt -t onedork -fs 95 -tfs 11 -nfs 115 -cellw 88% -T
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:

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:

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'
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())
@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)
import numpy as np
def argmax_nd(mat):
return np.unravel_index(mat.argmax(), mat.shape)
@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():