import sys

inputName = sys.argv[1] # input 1: SHVC 결과 txt 파일명
outputName = sys.argv[2] # input 2: 결과 출력으로 사용할 txt 파일명

txtFile = open(inputName, mode='r') # input 파일의 이름, mode='r'을 통해 파일을 읽음
txtFileWrite = open(outputName,mode='a') # output 파일의 이름, mode='a'를 통해 결과를 누적함

txtFileWrite.write('\n')

t = 0 # line 인덱스 정보 저장
p = -100
while True:
    line = txtFile.readline() # line에는 while문을 통해 input 파일의 1줄 부터 차례로 읽음
   
    if not line: # line이 없으면 while문 탈출
        break

    if line.find('SUMMARY') != -1 : # txt 파일 마지막에 있는 SUMMARY 위치 읽음
        p = t

    if t == p+2 or t == p+3 : # SUMMARY 다음줄과 그 다음줄을 읽고 출력함
        txtFileWrite.write(line.split()[3]+'\t'+line.split()[4] +'\t'+line.split()[5]+'\t'+line.split()[6]+'\t')
       
    t=t+1 # 현재의 line 인덱스


txtFileWrite.close()

tensorflow에서 훈련 과정을 시각화하기 위해 아래와 같은 코드를 작성 하였다

 

import matplotlib.pyplot as plt

~~~~~~
~~~~~~

hist = train_model.fit(~~~~~)

fig, loss_ax = plt.subplots()
acc_ax = loss_ax.twinx()
loss_ax.plot(hist.history['loss'], 'y', label='train loss')
loss_ax.plot(hist.history['val_loss'], 'r', label='val loss')

acc_ax.plot(hist.history['psnr'], 'b', label='train psnr')
acc_ax.plot(hist.history['val_psnr'], 'g', label='val psnr')

loss_ax.set_xlabel('epoch')
loss_ax.set_ylabel('loss')
acc_ax.set_ylabel('psnr')

loss_ax.legend(loc='upper left')
acc_ax.legend(loc='lower left')

plt.show()
   
    

 

현재 폴더에 존재하는 .py를 읽어오지 못하는 경우가 있다.

 

이러한 문제는 작업 환경이 현재폴더로 되어있지 않기 때문이다.

 

그러므로 다음 소스코드를 활용하여 작업 디렉토리를 원하는 위치로 변경시켜줄 필요가 있다.

 

import os

currentPath = os.getcwd() # 현재 디렉토리 위치를 반환한다.

os.chdir('change path') # 원하는 파일 경로로 변경 (ex. os.chdir('C:/Users/JSW/Desktop/'))

 

numpy 버전이 낮아서 생기는 문제이다.

 

pip install -U numpy

 

로 numpy 버전을 업데이트 해주면 해결된다.

+ Recent posts