Machine Learning

.text section을 image resizing 후 CNN 모델생성(1)

yssy431 2020. 8. 3. 11:45

기존에 했던 단순 0으로 채워넣거나 배열의 자르는 방식으로 resizing 했던 방식과는 다르게

tensorflow.image.resize 모듈을 사용해보기로 하였다.

https://www.tensorflow.org/api_docs/python/tf/image/resize 공식문서에서 발췌

여러가지 method가 있는대 어떠한 method가 가장 좋은지 모르겠으니 전부다 테스트 해보기로 결정

 

.text section data를 추출한 res_df의 data column에서 각 파일의 데이터 길이로 sqrt하여 reshape작업 

ex) file - > .text section의 총길이가 ->100 이면 10x10으로 reshape해주는 작업

image = res_df['data'].values
tmp = [] 
for x in tqdm(image):
    s = int(x.shape[0]*0.3)
    e = int(x.shape[0]*0.9)
    array = x[s:e].copy()
    length = int(np.ceil(np.sqrt(len(array))))
    array.resize(length*length)
    tmp.append(array.reshape(length,length))

모든 method를 사용해볼 예정이니 간단하게 리사이징 함수 생성

def img_resizing(array, length, res_method ):
    res = []
    for x in tqdm(array):        
        image = tf.constant(x)
        image = image[..., tf.newaxis]
        res.append(tf.image.resize(image,[length,length], method = res_method))
    return tf.stack([x for x in res])
    
bilinear  = img_resizing(tmp,64,'bilinear')
lanczos3 = img_resizing(tmp,64,'lanczos3')
lanczos5 = img_resizing(tmp,64,'lanczos5')
bicubic = img_resizing(tmp,64,'bicubic')
gaussian = img_resizing(tmp,64,'gaussian')
nearest = img_resizing(tmp,64,'nearest')
area = img_resizing(tmp,64,'area')
mitchellcubic = img_resizing(tmp,64,'mitchellcubic')

총 8가지의 메소드로 img resize작업

resizing 작업 후 CNN모델 테스트 바로 진행예정