상세 컨텐츠

본문 제목

Terminal 실행 시 Train Log 저장 및 실시간 출력 (save and stream)

개발/개발환경설정

by Matthew0633 2022. 5. 30. 15:14

본문

아래와 같이 모델학습을 위한 Command Line을 Terminal 에서 실행할 때,

# (Windows Powershell) 
(myconda) PS C:\Users\user> python train_vit.py --dataset POC

Terminal 에 출력되는 Log를 저장하고 싶을 때 유용한 방법에 대해 소개하고자 한다.

( 나의 경우는, 부서 사람들에게 공유목적으로, 연구를 수행한 후 Train Log까지 GitLab Project에 함께 push하고 있다)

그리고, 코드 내에 사용자가 Log 를 출력코드를 포함하고 있다고 가정한다 ^^;;

Command Line을 실행했을 때, Train Log를 파일로 저장함과 동시에 실시간으로도 Terminal 환경에 출력하기 위해서 아래 과정대로 수행한다. Windows Powershell 기준으로 설명하고, 마지막에 Ubuntu 에서 가능한 방법을 소개하고자 한다.

 

Windows Powershell (+VScode - 선택사항)

  1. VScode default terminal 설정 : (Windows10) Powershell
    • (VScode에서) F1 → Terminal: Select default profile → Powershell
  2. 관리자 권한 Powershell 실행
  3. ExecutionPolicy 수정
PS C:\Users\user> Set-ExecutionPolicy -ExecutionPolicy Unrestricted
(이후 "Y" or "y" 입력)

4. conda 명령어 사용 설정

PS C:\Users\user> conda init
PS C:\Users\user> conda activate myconda
(myconda) PS C:\Users\user>

5. 명령 실행: save log & print real time

# (Windows Powershell) 
(myconda) PS C:\Users\user> python train_vit.py --dataset POC | tee -filepath ./logs/train_vit_train_log.txt

 

Ubuntu (Linux)

# ubuntu 도 가능; log 저장에 명령어는 제외됨
$ python train_vit.py --dataset POC | tee outfile

 

<Reference>

https://blog.naver.com/PostView.nhn?blogId=roboholic84&logNo=221911267868&redirect=Dlog&widgetTypeCall=true&directAccess=false

https://askubuntu.com/questions/981016/direct-output-from-a-command-to-a-file-including-the-original-command-and-print

'개발 > 개발환경설정' 카테고리의 다른 글

관련글 더보기

댓글 영역