블로그 이미지
Flying Mr.Cheon youGom

Recent Comment»

Recent Post»

Recent Trackback»

« 2025/12 »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

 
 

https://yougome.tistory.com/558

 

은근히 시간이 걸린 내용이라 정리해 두려고 한다.

LSTM을 살펴보면 대부분 Sequence layer를 활용해서 설명하고 있어서,

찾는시간에도, 오류를 잡고, 내용을 이해하는데에도 시간이 좀 들었다.

주요 오류는 Input(...) 다음에 LSTM(...) 을 읽는 위치에서 계속 막혔다.

inputs = Input(shape=( ..., ))

outputs = LSTM(1, ... )(inputs) 

오류의 포인트는 shape 값 때문이었다.

찾아봐도 명쾌한 답이 잘 안나오니 답답할 뿐이었다.

 

대부분 알고 있겠지만, LSTM의 shape의 의미는 size, seq, feature다. 

이 내용을 토대로 계속 입력하지만 계속 오류가 발생한다.

여기서 오류를 범할 수 있는 부분이 바로, size 부분이다. input shape를 seq, feautre로 두고 처리하면 해결된다.

 

size는 결국에 model을 compile한 후, fit을 할 때 사용되는 loop의 크기로 보면 좋을 것 같다.

 

이렇게 간단히 해결될 것을.. 왜이리 오래 걸렸을까?

기본 tutorial 코드를 보면, LSTM( ) 함수에는 몇가지 추가된 파라미터들이 있다.

stateful, return_sequence 등을 추가되어 있다.

입문자나 초보자 입장에서는 이게 없으면 안될 것 같은,,

느낌적인 느낌때문에 지운 후 쓰기도 그대로 쓰기도

어떻게 할지 몰라서 망설여지게 된다.

 

오류를 잘 살펴보면, stateful을 쓰려면 batch_input_shape 쓰라고 하고,

batch_input_shape를 빼면, input_shape가 맞지 않다고 하니,

어느 장단에 맞춰야할지 무척 난감해진다.

 

에러를 해석해보면,

stateful은 batch의 총 크기를 알았을 때 안정적으로 사용할 수 있다는 것이고,

stateful을 쓰지 않는다면, 굳이 없어도 동작한다. ( 확인했음 )

 

즉, Model의 Input(...) 이용해서 LSTM을 처리하고자 한다면 아래 두개 코드중에 하나를 선택해서 쓰면되겠다.

간단한 코드가 좋으니.. 아래와 같이 정리한다.

첫줄의 Input(..)함수의 batch_shape shape부분을 살펴보면 좋겠다.

 

# stateful 파라미터를 쓰고 싶다! 그러면 batch_shape로 하면된다.

#site : https://yougome.tistory.com/558

input_tensor = Input(batch_shape=(1, 10, 2, ))
hidden_tensor = LSTM(1, batch_input_shape=(1, 10, 2), stateful=True, return_sequences=True )(input_tensor)
hidden_tensor = LSTM(1, stateful=True)(hidden_tensor)
output_tensor = Dense(2, )(hidden_tensor)
m_model = Model(inputs=input_tensor, outputs = output_tensor)
m_model.summary()

 

# stateful 파라미터에 관심없다! 동작만 하면된다!! 그러면 shape로 하면된다.

#site : https://yougome.tistory.com/558

input_tensor = Input(shape=(10, 2, ))
hidden_tensor = LSTM(1, input_shape=(10, 2), return_sequences=True )(input_tensor)
hidden_tensor = LSTM(1)(hidden_tensor)
output_tensor = Dense(2)(hidden_tensor)
m_model = Model(inputs=input_tensor, outputs = output_tensor)
m_model.summary()

 

위에 있는 코드가 좀 더 상세히 쓴 것이고,

케라스의 특성상, 이전에 입력받은 Layer는 다음 Layer에서 알아서 척척(?) 잘 받아주니,

아래 처럼 써도 전혀 문제가 없다.

 

# stateful 파라미터를 쓰고 싶다! 그러면 batch_shape로 하면된다.

#site : https://yougome.tistory.com/558

input_tensor = Input(batch_shape=(1, 10, 2, ))
hidden_tensor = LSTM(1, stateful=True, return_sequences=True )(input_tensor)
hidden_tensor = LSTM(1, stateful=True)(hidden_tensor)
output_tensor = Dense(2, )(hidden_tensor)
m_model = Model(inputs=input_tensor, outputs = output_tensor)
m_model.summary()

summary 결과 값 보고 싶다면, 아래 '더보기' 클릭

더보기

Model: "model_x"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_24 (InputLayer)        (1, 10, 2)                0         
_________________________________________________________________
lstm_30 (LSTM)               (1, 10, 1)                16        
_________________________________________________________________
lstm_31 (LSTM)               (1, 1)                    12        
_________________________________________________________________
dense_11 (Dense)             (1, 2)                    4         
=================================================================
Total params: 32
Trainable params: 32
Non-trainable params: 0
_________________________________________________________________

 

# stateful 파라미터에 관심없다! 동작만 하면된다!! 그러면 shape로 하면된다.

#site : https://yougome.tistory.com/558

input_tensor = Input(shape=(10, 2, ))
hidden_tensor = LSTM(1, return_sequences=True )(input_tensor)
hidden_tensor = LSTM(1)(hidden_tensor)
output_tensor = Dense(2)(hidden_tensor)
m_model = Model(inputs=input_tensor, outputs = output_tensor)
m_model.summary()

summary 결과 값 보고 싶다면, 아래 '더보기' 클릭

더보기

Model: "model_x" 
_________________________________________________________________ 
Layer (type)                 Output Shape              Param #    
================================================================= 
input_23 (InputLayer)        (None, 10, 2)             0          
_________________________________________________________________ 
lstm_28 (LSTM)               (None, 10, 1)             16         
_________________________________________________________________ 
lstm_29 (LSTM)               (None, 1)                 12         
_________________________________________________________________ 
dense_10 (Dense)             (None, 2)                 4          
================================================================= 
Total params: 32 
Trainable params: 32 
Non-trainable params: 0

 

 

아차, 다 쓰고 나서 읽어보니, 헷갈릴 수 있는 부분이 있어서 덧붙인다.

 

input의 shape 크기가 ( 10, 2 ) 인지,

output의 shape 크기가 2 인지,

>> input shape는 2개의 특징을 가진 10개의 연속된 데이터 N개를 사용하고 있고,

>> ouput shape는 2개의 특징으로 분류되는 N의 결과값을 사용하고 있다

 

( 10, 2 ) 이 부분은 큰 의미는 없고,

model 관련 dummy data로 테스트하던 중에 사용하던 코드여서,

그대로 붙여넣게 되었다.

 

ref : https://keras.io/getting-started/functional-api-guide/

:
그냥, 경함담..(?) ㅋ

딱 봐도, 나중에 모두 고생길로 가는 지시였다.
그럼에도 불구하고, 그냥 하는거다. ^^;

UI부분과 Network 리소스 관리에 대한 이야기다. 

UI에서 화면에 출력할 서버 데이터가 필요해 Data network 모듈에 Request를 호출한다.
너무 많이 호출( 100개 )하면 Request Queue가 Full나서 뻑난다.
그리하여, UI에서 Request 호출을 Pooling해서 Network 단에 하나씩 넘겨주라고 한다.
( 즉, 10개의 Request가 있으면, 1번 끝나면 2번 보내기 ... )

왜.. Network의 Sender( Request ) Pooling관리를 UI에서 하는지 모르겠다.
죽는 건 Network단인데, 고치는 건 UI다.

현재 1개의 UI에서 아랫단을 대신하여 만들고 있지만, 이거 하나로 모든 UI 페이지가 이 내용을 따라야 할 것이다.

약 30개 이상의 UI가 존재한다. Network에서 Pooling을 지원해주면 될 것을..
( 100줄에 끝날 내용을.. 200줄에서 최대 1만줄을 할애하는 것이다. )

이에 대한 건의는 하지 않는다. 윗분들은 제안을 좋아하지 않기 때문이다. 제안을 좋아하는 경우는 단 하나, 그 사람이 내고 싶어했던 제안을 내야 좋아한다.

그냥.. 닥치고 하라는 대로 한다.

위 지시에 대한 응답은 "알겠습니다"였다. 
나는..? 우리는..! 프로그래머가 아니라, 직장인이다.

ps. MVC보다는 Model2 Architecture와 가장 유사하다.
( 설계도는 없다. 그냥.. 아키텍쳐로 따지자면 그렇다는 것.. ^^;; 이해를 돕기 위해 비유했다. ^^; )


  


 























닥치고 정치를 하던가, 닥치고 하라는대로 하던가. 골라야 할듯 ^^;;


:

[Yawning Lady] Imitating a model explanation

외국어 학습 | 2012. 2. 13. 23:43 | Posted by youGom
The photography looks like it was taken in a lecture hall. The atmosphere looks very disorderly because there are people sitting and standing around the class. The people are probably attending a lecture but not all of them are listening to the lecture.
 Let's look at the woman in the photograph. She is wearing a dark purple beanie over her blond hair. She is wearing a brown sweater under her green overalls. You can see that she is yawning and frowning at the same time. Her eyes are closed. She must be very tired. She has a ring on her third finger and is holding a pen.
 You cannot see the background very well because it is blurry but there are people sitting and standing behind her There is another woman sitting behind her and that woman is looking towards the front. She is wearing a red sweater. She has a book open and is probably listening to the lecture at the front.
 There is a man sitting further back. He looks like he is writing something down. It's almost certainly winter because people are wearing heavy clothes. 

'외국어 학습' 카테고리의 다른 글

[ArrowEnglish] 알파벳의 정체  (0) 2014.09.02
:

[책] 비지니스 모델

책/독서후정리 | 2012. 2. 13. 15:33 | Posted by youGom
 

김영한 저, 해리티지 출판

페이스 북, 징가, 구루폰, 구글, 마이크로소프트, 포스퀘어.

소셜, 게임, 재미, 소사이어티( 사회성 ), 창의성, 위치정보, ...





: