Giter Site home page Giter Site logo

[Errno 9] Bad file descriptor about bbopt HOT 2 OPEN

evhub avatar evhub commented on August 15, 2024
[Errno 9] Bad file descriptor

from bbopt.

Comments (2)

evhub avatar evhub commented on August 15, 2024

@sakalouski I can't seem to replicate your error, but I suspect that has to do with the operating system and Python version you're running on, since it seems like the error is occurring when BBopt tries to lock the data file (which is a necessary step--it won't work if you comment out self._load_data()). It's also possible that there's something different about the code you're actually running and the version of the code you posted here that I ran. This is the code I ran:

import keras
from keras.optimizers import Nadam
from keras.layers import Input, Dense, Dropout
from keras.callbacks import EarlyStopping, ReduceLROnPlateau
from keras.metrics import mse
from sklearn import datasets
import pandas as pd
from tqdm import tqdm
from bbopt import BlackBoxOptimizer

bb = BlackBoxOptimizer(__file__)

iris = datasets.load_iris()

X = iris.data
Y = iris.target

train_split = int(.6*len(X))

X_train, X_val = X[:train_split], X[train_split:]
Y_train, Y_val = Y[:train_split], Y[train_split:]


def run_trial():
    """Run one trial of hyperparameter optimization."""
    # Start BBopt:
    bb.run()
    input_shape = 4

    h_n_num = bb.randint('num_neur',5,1000)
    act = bb.choice('activ_func',['selu','relu','elu'])
    num_lay = bb.randint('num_hidden_layers',0,10)
    dout = bb.uniform("dropout", 0, 1)
    lr = bb.uniform("init_learn_rate", 1e-5, 0.1)
    bsize = bb.choice('batch_size',[8,16,32,64,128])

    # Create model:
    a = Input(shape=(input_shape,))
    b = Dense(h_n_num,activation=act)(a)
    b = Dropout(dout)(b)
    for l in range(num_lay):
        b = Dense(h_n_num,activation=act)(b)
        b = Dropout(dout)(b)
    output = Dense(1,activation='linear',name='out')(b)

    model = keras.models.Model(inputs=a, outputs=output)
    opt = Nadam(lr)
    model.compile(optimizer = opt, loss=mse)

    # Train model:
    history = model.fit(x=X_train[:-70], y=Y_train[:-70],batch_size=bsize,epochs=1,
                              validation_data=(X_train[-70:],Y_train[-70:]),
                                 verbose=0,
                                 validation_split = 0.4,
                                 callbacks=[EarlyStopping(patience=30),
                                            ReduceLROnPlateau(monitor='val_loss', factor=0.5, patience=25,verbose=0)],
                                 shuffle=False)

    train_loss = history.history["loss"][-1]
    val_loss = history.history["val_loss"][-1]

    bb.remember({
        "train_loss": train_loss,
        "val_loss": val_loss,
    })

    bb.minimize(val_loss)

num_trials = 5
result = []

for i in tqdm(range(num_trials)):
    run_trial()
    result.append(bb.get_current_run())
    if len(result)>1:
        [i['memo'].update(i['values']) for i in result]
    temp = [i['memo'] for i in result]
    pd.DataFrame(temp).to_csv('./patch_weekly_5000_trials.csv')

Do you get an error when you run this code?

from bbopt.

evhub avatar evhub commented on August 15, 2024

@sakalouski Also, if you could try updating your bbopt to 0.4.2 (pip install -U bbopt) and let me know what the error message you get then is, that would be greatly appreciated.

from bbopt.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.