In this article, I will share some of my experience on installing NVIDIA driver and CUDA on Linux OS. Here I mainly use Ubuntu as example. Comments for CentOS/Fedora are also provided as much as I can.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def show_img_from_batch(batch): | |
img = transforms.ToPILImage()(batch[0]) | |
plt.figure() | |
plt.imshow(img) | |
plt.show() |