@@ -65,14 +65,17 @@ def download_model_file():
6565 except Exception as e :
6666 print (f"{ file_path } download fail : { e } " )
6767
68- download_model_file ()
68+ # download_model_file()
6969
7070# 경로
7171sentiment_path = 'DataSets/upstock-sentiment-data.csv' # sentiment data
7272tokenizer_path = 'SaveModel/upstock_sentiment_tokenizer.pickle'
7373model_path = 'SaveModel/upstock_sentiment_model.keras'
7474model_path_h5 = 'SaveModel/upstock_sentiment_model.h5' # compatibility issue .h5
7575
76+ # TODO 근거
77+ model_pkl_path = 'SaveModel/upstock_sentiment_pkl.pkl' # import matplotlib.pyplot as plt
78+
7679# load file < predict task에는 필요없음
7780def load_file (path , description ):
7881 if os .path .exists (path ):
@@ -290,22 +293,21 @@ def load_pickle(path, description):
290293 tensorboard = TensorBoard (log_dir = 'LogFile/Log{}' .format ('_SentimentModel_' + str (int (time .time ()))) )
291294 early_stop = EarlyStopping (monitor = 'val_loss' , patience = 3 , restore_best_weights = True , verbose = 1 ) # early stop alarm
292295
293- # 학습
294- model .fit (
296+ # history => pkl
297+ history = model .fit (
295298 X_train , y_train ,
296299 validation_data = (X_val , y_val ),
297300 batch_size = 32 ,
298301 epochs = 20 ,
299302 callbacks = [early_stop , tensorboard ]
300303 )
301304
302- # TEST
303305 model .summary ()
304306
305307 # save
306308 try :
307309 model .save (model_path )
308- model .save (model_path_h5 )
310+ # model.save(model_path_h5) # h5 version
309311 except Exception as e :
310312 print (f'model save fail : { e } ' )
311313
@@ -314,3 +316,11 @@ def load_pickle(path, description):
314316 pickle .dump (tokenizer , f )
315317 except Exception as e :
316318 print (f'tokenizer save fail : { e } ' )
319+
320+ try :
321+ with open (model_pkl_path , 'wb' ) as f :
322+ pickle .dump (history .history , f ) # matplot
323+ except Exception as e :
324+ print (f'model pkl save fail : { e } ' )
325+
326+
0 commit comments