Skip to content

Instantly share code, notes, and snippets.

@YoelShoshan
YoelShoshan / extract_tensorboard_tensorflow_rfrecords.py
Created May 29, 2022 07:47
Extract events from tensorboards tfrecords events file
import tensorflow as tf
from collections import defaultdict
def process_tensorboard_events_file(tensorboard_events_filename, tf_version=2, tags=None):
assert isinstance(tags, list)
for v in tags:
assert isinstance(v, str)
it = _get_events_iterator(tensorboard_events_filename, tf_version)
ans = defaultdict(list)
for event in it:
@YoelShoshan
YoelShoshan / volume_rendering_vtk.py
Created May 1, 2021 05:24 — forked from somada141/volume_rendering_vtk.py
Volume rendering in Python using VTK-SimpleITK #python #visualization #vtk #simpleitk #itk
#!/usr/bin/python
import SimpleITK as sitk
import vtk
import numpy as np
from vtk.util.vtkConstants import *
def numpy2VTK(img,spacing=[1.0,1.0,1.0]):
# evolved from code from Stou S.,
@YoelShoshan
YoelShoshan / base.py
Created October 26, 2019 19:22
Rendering osmesa (ofscreen mesa) opengl scene of ODE (physics engine) simulation
import abc
import six
@six.add_metaclass(abc.ABCMeta)
class Platform(object):
"""Base class for all OpenGL platforms.
Parameters
import cv2
import numpy as np
def base_tens_stats(tens):
print(f'shape={tens.shape} min={tens.min()} mean={tens.mean()} max={tens.max()}')
x = np.random.randint(0,1020, (256,256,20)).astype(np.uint16)
base_tens_stats(x)
def make_parallel(fn, num_gpus, inputs_to_be_splitted, inputs_to_be_passed_as_is=None):
'''
Converts a function into a parallel version of it, using a simple syncronized data parallelsim
:param fn: a tensorflow function
:param num_gpus: number of gpus
:param inputs_to_be_splitted: a dict with all of the tensorflow variables/placeholders that will be split before being passed to fn
:param inputs_to_be_passed_as_is: a dict with all of the variables that will be passed as is to fn
:return:
'''
@YoelShoshan
YoelShoshan / pyside_networkx_graphviz_interactive_graph.py
Created September 18, 2017 19:12
simple standalone script for pyside + networx + graphviz layout of an acyclic directed graph
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import networkx as nx
from networkx.drawing.nx_agraph import graphviz_layout
class ZedNode(QGraphicsEllipseItem):
rad = 5
def __init__(self, key):
@YoelShoshan
YoelShoshan / reproducible_image_dim_ordering_issue.py
Created October 17, 2016 18:56
reproducible image_dim_ordering convergence issue
from keras import backend as K
import keras.optimizers
from keras.layers import Convolution2D, MaxPooling2D
from keras.layers import Activation, Dropout, Flatten, Dense, Input
from keras.models import Model
import numpy as np
def make_model(input_dim_size):
if K.image_dim_ordering() == 'tf':
input_shape = (input_dim_size, input_dim_size,1)