Naver-AI-Hackathon / AI-Vision

67 stars 34 forks source link

자동으로 submit 할 수 있는 봇 코드를 공유합니다. #302

Open DaehunGwak opened 5 years ago

DaehunGwak commented 5 years ago

아직 완전하진 않지만, 한 시간마다 밤을 새며 제출하는 분이 있으실까봐,
조금이라도 도움이 될 수 있도록 코드를 공유합니다.
혹시나 이상한 점이나 개선할 사항있으면 바로 고치도록 하겠습니다! 그럼 본선에서 만나요 👍

-24시간이모자라, 곽대훈-

forestnoobie commented 5 years ago

감사합니다. 안 그래도 위와 같은 기능이 있으면 좋겠다고 생각했었는데 공유해주셔서 감사합니다!

ttagu99 commented 5 years ago

대훈님 감사요~. 아래는 대훈님 코드에서 파일로 가져다 쓰게끔 변경했습니다~.

image 위에서 부터 순서대로 submit 하게 됩니다.


import os
import sys
import time
import subprocess
from multiprocessing import Process
from datetime import datetime
import pandas as pd

team_name = "Zonber"       
data_name = "ir_ph2"     
start_wait_sec =  0
submit_list_path  = './submit_list.csv'

def run_submit(command):
    now = time.time()
    print(f"[Command] {command}")
    print(datetime.now())
    subprocess.call(command)
    print(f"[Collapsed time] {time.time() - now}")

if __name__ == "__main__":
    S_HOUR = 3601
    li_procs = []

    while(1):
        s_df = pd.read_csv(submit_list_path)
        for i in range(s_df.shape[0]):
            s = s_df.session[i]
            m = s_df.model[i]
            full_session = '/'.join([team_name, data_name, str(s)])
            full_command = f"nsml submit {full_session} {m}"
            li_procs.append(Process(target=run_submit, args=(full_command, )))

        now = time.time()
        time.sleep(start_wait_sec)

        for i, proc in enumerate(li_procs):
            proc.start()
            if i + 1 < len(li_procs):
                time.sleep(S_HOUR)

        for proc in li_procs:
            proc.join()
        print(f"Total collapsed time: {time.time() - now}")
        s_df.drop(s_df.index, inplace=True)
        s_df.to_csv(submit_list_path)
DaehunGwak commented 5 years ago

@ttagu99 오 대우님 감사합니다! 제 코드에 실례가 안된다면 반영해 놓아도 괜찮을까요?

ttagu99 commented 5 years ago

@ttagu99 오 대우님 감사합니다! 제 코드에 실례가 안된다면 반영해 놓아도 괜찮을까요?

네네~. 물론입니다~~