9/24/2022

torch np cuda seed random everything

 

refer to below code:


..

import numpy as np
import os
import random
import torch

SEED = 42

def seed_everything(seed):
random.seed(seed)
os.environ['PYTHONHASHSEED'] = str(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True

seed_everything(SEED)

..


Thank you.

www.marearts.com

9/23/2022

c++ 'time_t' to 'yyyy mm dd', 'tm' to 'time_t' , example source code

 


refer to bloew example code:


..

//current day of second from 1900.01.01
    time_t current_time;
    current_time = time(NULL);
    printf("%ld seconds since January 1, 1900\n", current_time);

    //time_t to yyyy mm dd
    char buffer[80];
    strftime(buffer, 20, "%Y-%m-%d %H:%M:%S", localtime(&current_time));
    printf("%s", buffer);

    //make timt_t from custome yyyy mm dd
    struct tm s_tm = { 0 };
    s_tm.tm_year = 2022 - 1900;
    s_tm.tm_mon = 9 - 1;
    s_tm.tm_mday = 23;
    time_t s_tmt = mktime(&s_tm);
    printf("s_tmt %ld \n", s_tmt);

    /*
    struct tm {
        int tm_sec;         // seconds
        int tm_min;         // minutes
        int tm_hour;        // hours
        int tm_mday;        // day of the month
        int tm_mon;         // month
        int tm_year;        // year
        int tm_wday;        // day of the week
        int tm_yday;        // day in the year
        int tm_isdst;       // daylight saving time
    };
    */

..


Thank you.

www.marearts.com

9/16/2022

python float variable Decimals format

 

refer to example code

..

print(f'{my_var:.1f}')
print(f'{res_dict}, total:{total_end - total_start:.3f} , ready:{end_ready - total_start:.3f}, inference:{end_inference - start_inference:.3f}')

..


Thank you.


www.marearts.com

9/01/2022

Delete 100mb file in all committed history in git

 Let's say the problem which is more than 100mb file is "shit.pt"

And you want to delete already committed in git history and you don't push and reverting.

Then this is save you


> git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch SHIT.bin' --prune-empty --tag-name-filter cat -- --all


Change SHIT.bin file name as your problem guy. 

And add .gitignore and commit & push.

Thank you.

www.marearts.com



8/26/2022

finding all specific extension file in all subfolder from starting directory

 refer to example code

..

import os
from glob import glob

start_dir = '/start/folder' #os.getcwd()
pattern = "*.jpg" #file extension which you want to find

for dir,_,_ in os.walk(start_dir):
print( glob(os.path.join(dir,pattern)) )

..


Thank you.

www.marearts.com


8/25/2022

use easy attribute class using "argparse", "ArgumentParser"

 see the example code

.

import argparse

#define as default
paser = argparse.ArgumentParser()
args = paser.parse_args("")

#assign values
args.cuda = False
args.device = 'cpu'

#print
print(args)
print(args.cuda)

.


Thank you.

www.marearts.com