Skip to content

Instantly share code, notes, and snippets.

View ihoromi4's full-sized avatar

Ihor Omelchenko ihoromi4

View GitHub Profile
@ihoromi4
ihoromi4 / images_to_zip.py
Last active February 5, 2020 12:09
convert numpy images to zip
import os
import zipfile
import numpy as np
import cv2
def images_to_zip(images: list, out_filename: str):
if os.path.exists(out_filename):
print('File', out_filename, 'already exists. Abort.')
return
@ihoromi4
ihoromi4 / seed_everything.py
Created February 5, 2020 11:49
pytorch - set seed everything
def seed_everything(seed: int):
import random, os
import numpy as np
import torch
random.seed(seed)
os.environ['PYTHONHASHSEED'] = str(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
@ihoromi4
ihoromi4 / get_device_method.py
Last active February 5, 2020 11:50
pytorch - get nn.Module device method
from torch import nn
class NN(nn.Module):
def device(self):
return next(self.parameters()).device
@ihoromi4
ihoromi4 / get_n_params.py
Created February 5, 2020 11:45
pytorch - get number of a model parameters
import functools
import operator
from torch import nn
def get_n_params(model: nn.Module) -> int:
return sum((functools.reduce(operator.mul, p.size()) for p in model.parameters()))
import tensorflow as tf
from keras.backend.tensorflow_backend
config = tf.ConfigProto(device_count={'CPU': 1})
session = tf.Session(config=config)
tensorflow_backend.set_session(session)
@ihoromi4
ihoromi4 / main.go
Created May 18, 2018 10:51
golang multicast client-server
package main
import (
"encoding/hex"
"log"
"net"
"time"
)
const (