Skip to content

Instantly share code, notes, and snippets.

View qmaruf's full-sized avatar
🤖
Training robot

Quazi Marufur Rahman qmaruf

🤖
Training robot
View GitHub Profile
class NetLong(nn.Module):
def __init__(self):
super(NetLong, self).__init__()
self.fcs = self.make_layers()
def forward(self, x):
x = self.fcs(x)
return x
def make_layers(self):
@qmaruf
qmaruf / pickle
Last active January 24, 2020 05:13
import _pickle as pickle
class Pickle:
def __init__(self):
pass
def save_data(self, data, fpath):
with open(fpath, 'wb') as hndl:
pickle.dump(data, hndl, -1)
@qmaruf
qmaruf / Install NVIDIA Driver and CUDA.md
Created November 14, 2019 02:20 — forked from wangruohui/Install NVIDIA Driver and CUDA.md
Install NVIDIA Driver and CUDA on Ubuntu / CentOS / Fedora Linux OS
def plot_us(imgs, titles=None):
fig, axs = plt.subplots(nrows=1, ncols=len(imgs), figsize=(15, 15))
axs = np.array(axs).reshape(1, -1)
for i, img in enumerate(imgs):
axs[0, i].imshow(img)
if titles not None:
axs[0, i].set_title(titles[i])
axs[0, i].set_axis_off()
plt.grid()
plt.show()
import numpy as np
import h5py
with h5py.File('data.h5', 'w') as hndl:
hndl['mystring'] = 'hello world!'
with h5py.File('data.h5', 'r') as hndl:
print (hndl['mystring'].value)
import matplotlib
matplotlib.use('TkAgg')
import ntpath
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
img = image_np.copy()/255.0
im_height, im_width, _ = img.shape
print (width, height)
for boxes, classes, scores in zip(output_dict['detection_boxes'], output_dict['detection_classes'], output_dict['detection_scores']):
if classes == 1 and scores >= 0.5:
ymin, xmin, ymax, xmax = boxes
xmin, xmax, ymin, ymax = xmin * im_width, xmax * im_width, ymin * im_height, ymax * im_height
xmin, xmax, ymin, ymax = int(xmin), int(xmax), int(ymin), int(ymax)
print (left, right, top, bottom)
def draw_rectangle(path, x1, y1, x2, y2):
im = np.array(Image.open(path), dtype=np.uint8)
fig,ax = plt.subplots(1)
ax.imshow(im)
rect = patches.Rectangle((x1,y1),x2-x1,y2-y1,linewidth=1,edgecolor='r',facecolor='none')
ax.add_patch(rect)
plt.show()
def run_inference_for_multiple_images2(images, graph):
output_dicts = []
with graph.as_default():
with tf.Session() as sess:
for image in images:
# print (image)
ops = tf.get_default_graph().get_operations()
all_tensor_names = {output.name for op in ops for output in op.outputs}
tensor_dict = {}
def show_img_from_batch(batch):
img = transforms.ToPILImage()(batch[0])
plt.figure()
plt.imshow(img)
plt.show()