hyperasを使用してMLPのパラメータチューニングを自動調整したいのですがエラーが出てプログラムを回すことができません.エラーを消すにはどのようにすればよいでしょうか?
以下にソースコードとエラー,参照したurlを添付します.
python
1"""importするもの""" 2!pip install hyperas 3!pip install hyperopt 4!pip install h5py 5!pip install -U -q PyDrive 6 7from hyperopt import Trials, STATUS_OK, tpe 8from hyperas import optim 9from hyperas.distributions import choice 10 11import tensorflow as tf 12from tensorflow.keras.models import Sequential 13from tensorflow.keras.layers import Activation, Dense, Dropout, LeakyReLU 14from tensorflow.keras import regularizers 15from tensorflow.keras.optimizers import Adagrad 16from tensorflow.keras.optimizers import Adam 17from tensorflow.keras.models import load_model 18from keras.regularizers import l1, l2 19from keras import regularizers 20from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint, CSVLogger 21 22from sklearn.model_selection import train_test_split 23import numpy as np 24import os 25import time 26import csv 27import cv2 28import math 29 30from pydrive.auth import GoogleAuth 31from pydrive.drive import GoogleDrive 32from google.colab import auth 33from oauth2client.client import GoogleCredentials 34 35auth.authenticate_user() 36gauth = GoogleAuth() 37gauth.credentials = GoogleCredentials.get_application_default() 38drive = GoogleDrive(gauth) 39 40#hyperasファイル 41fid = drive.ListFile({'q':"title='hyperas.ipynb'"}).GetList()[0]['id'] 42f = drive.CreateFile({'id': fid}) 43f.GetContentFile('hyperas.ipynb') 44 45#ファイルの入出力 46os.chdir('/content/drive/My Drive/Colab Notebooks/my_drive/deep_learning_google') 47 48X=[] 49Y=[] 50 51#def prepare_data(): 52#画像(入力データ) 53X = np.load('data/numpy/pictures_120x120.npy') 54#座標(出力データ) 55location = np.loadtxt("data/coordinates_data/sigma_x/max_stress_coordinates_a.csv",delimiter=",",skiprows=0) 56Y.extend(location) 57location = np.loadtxt("data/coordinates_data/sigma_x/max_stress_coordinates_b.csv",delimiter=",",skiprows=0) 58Y.extend(location) 59location = np.loadtxt("data/coordinates_data/sigma_x/max_stress_coordinates_c.csv",delimiter=",",skiprows=0) 60Y.extend(location) 61location = np.loadtxt("data/coordinates_data/sigma_x/max_stress_coordinates_d.csv",delimiter=",",skiprows=0) 62Y.extend(location) 63location = np.loadtxt("data/coordinates_data/sigma_x/max_stress_coordinates_e.csv",delimiter=",",skiprows=0) 64Y.extend(location) 65location = np.loadtxt("data/coordinates_data/sigma_x/max_stress_coordinates_f.csv",delimiter=",",skiprows=0) 66Y.extend(location) 67location = np.loadtxt("data/coordinates_data/sigma_x/max_stress_coordinates_g.csv",delimiter=",",skiprows=0) 68Y.extend(location) 69location = np.loadtxt("data/coordinates_data/sigma_x/max_stress_coordinates_h.csv",delimiter=",",skiprows=0) 70Y.extend(location) 71location = np.loadtxt("data/coordinates_data/sigma_x/max_stress_coordinates_i.csv",delimiter=",",skiprows=0) 72Y.extend(location) 73 74Y = np.array(Y) 75 76def prepare_data(): 77 x_train,x_test,y_train,y_test = train_test_split(X,Y,test_size=0.3) 78 return x_train, y_train, x_test, y_test 79 80def create_model(x_train, y_train, x_test, y_test): 81 82 model = Sequential() 83 model.add(Dense({{choice([1000,2000,3000])}}, 84 input_dim=14400,kernel_initializer='random_normal',bias_initializer='zeros')) 85 86 model.add(LeakyReLU()) 87 model.add(Dropout({{uniform(0,1)}})) 88 89 model.add(Dense({{choice([100,200,300,400,500,600,700,800,900,1000])}}, 90 kernel_initializer='random_normal',bias_initializer='zeros')) 91 model.add(LeakyReLU()) 92 model.add(Dropout({{uniform(0,1)}})) 93 94 model.add(Dense({{choice([100,200,300,400,500,600,700,800,900,1000])}}, 95 kernel_initializer='random_normal', 96 bias_initializer='zeros')) 97 model.add(LeakyReLU()) 98 model.add(Dropout(({{uniform(0,1)}}))) 99 100 model.add(Dense({{choice([50,150,200,250,300,350,400,450])}}, 101 kernel_initializer='random_normal',bias_initializer='zeros')) 102 model.add(LeakyReLU()) 103 model.add(Dropout(({{uniform(0,1)}}))) 104 105 model.add(Dense({{choice([10,20,30,40,50,60,70,80,90,100])}}, 106 kernel_initializer='random_normal',bias_initializer='zeros')) 107 model.add(LeakyReLU()) 108 model.add(Dropout(({{uniform(0,1)}}))) 109 110 model.add(Dense({{choice([5,10,15,20,25,30,40,45,50])}}, 111 kernel_initializer='random_normal',bias_initializer='zeros')) 112 model.add(LeakyReLU()) 113 model.add(Dropout(({{uniform(0,1)}}))) 114 115 model.add(Dense(2)) 116 model.add(Activation("linear")) 117 118 opt = Adam(lr=0.0001) 119 model.compile(loss="mean_absolute_percentage_error", 120 optimizer=opt) 121 history = model.fit(x_train,y_train, 122 nb_epoch=200, 123 batch_size=32, 124 verbose=1, 125 validation_data=(x_test,y_test)) 126 return {'loss': val_loss, 'status': STATUS_OK, 'model': model} 127 128if __name__=="__main__": 129 130 best_run,best_model = optim.minimize(model=create_model, 131 data=prepare_data, 132 algo=tpe.suggest, 133 max_evals=200, 134 trials=Trials()) 135 136 print(best_model.summary()) 137 print(best_run) 138 _, _, x_test, y_test = prepare_data() 139 val_loss, val_acc = best_model.evaluate(x_test, y_test) 140 print("val_loss: ", val_loss)
error
1--------------------------------------------------------------------------- 2FileNotFoundError Traceback (most recent call last) 3<ipython-input-5-379c67ff7b07> in <module>() 4 132 algo=tpe.suggest, 5 133 max_evals=200, 6--> 134 trials=Trials()) 7 135 8 136 print(best_model.summary()) 9 103 frames 11/usr/local/lib/python3.6/dist-packages/hyperas/optim.py in minimize(model, data, algo, max_evals, trials, functions, rseed, notebook_name, verbose, eval_space, return_space, keep_temp) 12 67 notebook_name=notebook_name, 13 68 verbose=verbose, 14---> 69 keep_temp=keep_temp) 15 70 16 71 best_model = None 17 18/usr/local/lib/python3.6/dist-packages/hyperas/optim.py in base_minimizer(model, data, functions, algo, max_evals, trials, rseed, full_model_string, notebook_name, verbose, stack, keep_temp) 19 96 model_str = full_model_string 20 97 else: 21---> 98 model_str = get_hyperopt_model_string(model, data, functions, notebook_name, verbose, stack) 22 99 temp_file = './temp_model.py' 23 100 write_temp_files(model_str, temp_file) 24 25/usr/local/lib/python3.6/dist-packages/hyperas/optim.py in get_hyperopt_model_string(model, data, functions, notebook_name, verbose, stack) 26 183 else: 27 184 calling_script_file = os.path.abspath(inspect.stack()[stack][1]) 28--> 185 with open(calling_script_file, 'r') as f: 29 186 source = f.read() 30 187 31 32FileNotFoundError: [Errno 2] No such file or directory: '/content/drive/My Drive/Colab Notebooks/my_drive/deep_learning_google/<ipython-input-5-379c67ff7b07>'
あなたの回答
tips
プレビュー