def pred_candlestick( self, model, output_png=None, classes=["0", "1"], img_size=[80, 80, 3], ): """ローソク足の画像作成して予測+gradcam""" # ラベルと株価取得 df, label_price = self.get_pred_df() # 画像出力 if self.is_2day_label or len(classes) == 4: make_candlestick.make_mav_candlestick_mplfinance(df, output_png) else: make_candlestick.make_candlestick_mplfinance(df, output_png) # 予測 y, pb = base_predict.pred_from_1img(model, output_png, img_size[0], img_size[1], classes=classes, show_img=True) # gradcam _ = grad_cam.image2gradcam(model, output_png) return y, pb, label_price, df
if p_args.mode == "predict": args = get_class_fine_tuning_parameter_base() pred_directory(args) if p_args.grad_cam_model_path is not None and p_args.grad_cam_image_dir is not None: args = get_class_fine_tuning_parameter_base() for i, p in tqdm( enumerate(util.find_img_files(p_args.grad_cam_image_dir))): # 50枚ごとにモデル再ロード if i % 50 == 0: keras.backend.clear_session() keras.backend.set_learning_phase(0) model = keras.models.load_model(p_args.grad_cam_model_path, compile=False) # p_args.grad_cam_image_dirと同じディレクトリにGradCAM画像出力 grad_cam.image2gradcam(model, p, is_gradcam_plus=False) if p_args.mode == "tuning": os.makedirs(p_args.tuning_output_dir, exist_ok=True) study = optuna.create_study( direction="minimize", study_name=p_args.study_name, storage= f"sqlite:///{p_args.tuning_output_dir}/{p_args.study_name}.db", load_if_exists=True, ) study.optimize( Objective(p_args.tuning_output_dir), n_trials=p_args.n_trials, timeout=60 * 30, # 1trial30分 )