hi.ipynb 7.3 KB

from models.yolo import *
PATH_WEIGHT = './models/best.pt'
PATH = '/root/Public/pretrained/best.pt'

net = Model('/root/helmet_det/yolov7-main/cfg/training/yolov7.yaml').to('cuda')
state_dict = torch.load(PATH, map_location='cuda')['model'].state_dict()
net.load_state_dict(state_dict, strict=False)

a = torch.load(PATH_WEIGHT, map_location='cuda')['model']
#print(a)
import torch
from utils.torch_utils import select_device

select_device
tensor([[[2, 0, 4],
         [1, 3, 2],
         [1, 2, 3]],

        [[4, 4, 0],
         [2, 2, 0],
         [1, 2, 0]],

        [[4, 1, 0],
         [4, 0, 2],
         [4, 4, 1]]])
a = a[[2, 1, 0], :, :]
print(a.shape, 4)
print(a)
torch.Size([3, 3, 3]) 4
tensor([[[4, 1, 0],
         [4, 0, 2],
         [4, 4, 1]],

        [[4, 4, 0],
         [2, 2, 0],
         [1, 2, 0]],

        [[2, 0, 4],
         [1, 3, 2],
         [1, 2, 3]]])
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randint(0, 50, size=(5000000, 4)), columns=('a','b','c','d'))
df.shape
# (5000000, 5)
df.head()
a b c d
0 46 37 22 8
1 19 38 11 10
2 15 22 40 30
3 5 31 34 45
4 46 47 2 46
import time 
start = time.time() # iterrows for idx, row in df.iterrows() 
for idx, row in df.iterrows():
    if row.a == 0 :         
        df.at[idx, 'e' ] = row.d     
    elif ( row.a <= 25 ) and (row.a > 0 ):         
        df.at[idx, 'e' ] = (row.b)-(row.c)     
    else :         
        df.at[idx, 'e' ] = row.b + row.c 
end = time.time()
print (end - start) ### 걸린 시간: 177초

    
451.1593863964081
# using vectorization 

start = time.time()
df['e'] = df['b'] + df['c']
df.loc[df['a'] <= 25, 'e'] = df['b'] -df['c']
df.loc[df['a']==0, 'e'] = df['d']
end = time.time()
print(end - start)
## 0.28007707595825195 sec
0.16010785102844238
import time

def yield_abc():
  for ch in "ABC":
    time.sleep(1)
    yield ch

for ch in yield_abc():
    print(ch)
A
B
C
False and device.type != 'cpu' 
False
False and True
False