Skip to content

Instantly share code, notes, and snippets.

View weiaicunzai's full-sized avatar
🎯
Focusing

weiaicunzai

🎯
Focusing
  • Beijing University of Posts and Telecommunications
  • Beijing, China
View GitHub Profile
@weiaicunzai
weiaicunzai / iter.py
Created December 11, 2018 04:53
iterate list every two elements
for x, y in zip(*[iter(line1)] * 2):
#line1(x0,y0,x1,y1)
#line1 -> (x0, y0), (x1, y1)
#. zip(*[iter(line1)] * 2)
#->zip(<tuple_iterator object at 0x10dafdb00>, <tuple_iterator object at 0x10dafdb00>)
def bb_intersection_over_union(boxA, boxB):
# determine the (x, y)-coordinates of the intersection rectangle
xA = max(boxA[0], boxB[0])
yA = max(boxA[1], boxB[1])
xB = min(boxA[2], boxB[2])
yB = min(boxA[3], boxB[3])
# compute the area of intersection rectangle
interArea = max(0, xB - xA + 1) * max(0, yB - yA + 1)
import cProfile
cProfile.runctx("yolo_data[13]", globals(), None)
@weiaicunzai
weiaicunzai / profiler.py
Last active December 31, 2023 06:24
using tensorflow Dataset api to do data_argument
import cProfile, pstats
from pstats import SortKey
sortby = SortKey.CUMULATIVE
with cProfile.Profile() as pr:
# your code here
ps = pstats.Stats(pr).sort_stats(sortby)
def _make_blocks(self, block_nums, layer_num, stride=2, block=RiRBlock):
layers = nn.Sequential()
in_channel = self.base
for block in range(block_nums):
layers.add_module("RiR_Block{}".format(block), RiRBlock(in_channel, self.base, layer_num, stride))
in_channel = self.base
self.base *= 2
return layers
@weiaicunzai
weiaicunzai / cifar100_mean_std.py
Created June 22, 2018 13:48
compute cifar100 mean and std
def compute_mean_std(cifar100_dataset):
"""compute the mean and std of cifar100 dataset
Args:
cifar100_training_dataset or cifar100_test_dataset
witch derived from class torch.utils.data
Returns:
a tuple contains mean, std value of entire dataset
"""
@weiaicunzai
weiaicunzai / accuracy.py
Created June 22, 2018 13:20
compute top1, top5 error using pytorch
from __future__ import print_function, absolute_import
__all__ = ['accuracy']
def accuracy(output, target, topk=(1,)):
"""Computes the precision@k for the specified values of k"""
maxk = max(topk)
batch_size = target.size(0)
_, pred = output.topk(maxk, 1, True, True)