Ejemplo n.º 1
0
        return self._par

    def get_hms(self):
        return self._hms

    def get_mpai(self):
        return self._mpai

    def get_mpap(self):
        return self._mpap

    def maximize(self):
        return self._maximize


if __name__ == '__main__':

    obj_fun = ObjectiveFunction()
    num_processes = cpu_count()  # use number of logical CPUs
    num_iterations = num_processes * 5  # each process does 5 iterations
    results = harmony_search(obj_fun, num_processes, num_iterations)

    print('Elapsed time: {}\nBest harmony: {}\nBest fitness: {}'.format(
        results.elapsed_time, results.best_harmony, results.best_fitness))

    # training & validation
    best_training(results.best_harmony, EMBED)

    # prediction
    prediction(results.best_harmony, EMBED)
Ejemplo n.º 2
0
        help="Usage mode: (training, prediction, test_model(folder))")
    parser.add_argument("-use_gpu",
                        metavar="G",
                        type=int,
                        default=-1,
                        help="Manually assign a gpu number")
    args = parser.parse_args()
    mode = args.mode
    use_gpu = args.use_gpu

    # load settings
    settings = {}
    path = "./meta_data.json"
    with open(path) as file:
        settings = json.loads(file.read())

    #TODO print stats

    # maybe print link to Tensorboard?
    print("Check out TensorBoard:  https://localhost:6006")

    #TODO set gpu
    torch.cuda.init()
    torch.cuda.set_device(0)

    if mode == "train":
        training.testfold_training(settings)
    elif mode == "predict":
        prediction.prediction(settings)
    #TODO train, test, predict
Ejemplo n.º 3
0
    'ependymoma', 'greymatter', 'glioblastoma', 'lowgradeglioma', 'lymphoma',
    'medulloblastoma', 'meningioma', 'metastasis', 'nondiagnostic',
    'pilocyticastrocytoma', 'pituitaryadenoma', 'pseudoprogression',
    'schwannoma', 'whitematter'
]

if __name__ == "__main__":

    # load a trained SRH model
    deepSRHmodel = load_model(args.model)

    # import SRH mosaic
    specimen = import_srh_dicom(args.strip_directory)
    print("SRH mosaic size is: " + str(specimen.shape))

    # generate preprocessed image patches
    patches = patch_generator(specimen, step_size=100, old_preprocess=True)
    del specimen

    # predict on patches
    specimen_prediction = prediction(
        feedforward(patch_dict=patches, model=deepSRHmodel))

    # print diagnosis
    print("SRH specimen diagnosis is: " +
          CLASS_NAMES[np.argmax(specimen_prediction)] + " (probability = " +
          str(np.max(specimen_prediction)) + ")")

    # display probability histogram
    plot_srh_probability_histogram(specimen_prediction)
Ejemplo n.º 4
0
from flask import Flask, render_template, json, request
from flask import jsonify

import nltk

from prediction.prediction import prediction
obj = prediction()
app = Flask(__name__)
pos = 0
neg = 0


@app.route('/predict', methods=['POST'])
def predict():
    text = request.json['feedback']
    global pos, neg
    result = obj.predict([text])
    print(result)

    word_freqs, max_freq = obj.word_cloud()

    response = {}
    response["word_freqs"] = str(word_freqs)
    response["max_freq"] = max_freq
    response["result"] = str(result)
    response["pos"] = pos
    response["neg"] = neg

    return jsonify(response)

Ejemplo n.º 5
0
    rand = Random()
    rand.seed(int(time.time()))
    es = ec.GA(rand)

    es.terminator = terminators.evaluation_termination
    es.observer = inspyred.ec.observers.stats_observer
    final_pop = es.evolve(generator=generate_design_variable,
                          evaluator=evaluate_optimization,
                          maximize=False,
                          pop_size=100,
                          bounder=inspyred.ec.Bounder([-100.0, -100.0, -100.0, -100.0, -100.0, -100.0, -100.0, -100.0, -100.0, -100.0, -100.0, -100.0, -100.0],
                                                      [100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0]),
                          max_evaluations=10000,
                          num_elites=1,
                          num_inputs=1)


if __name__ == '__main__':

    start_time = time.time()
    optimize_core()
    elapsed_time = time.time() - start_time

    print('Elapsed time: {}\nBest gene: {}\nBest fitness: {}'.format(elapsed_time, BEST_GENE, BEST_FITNESS))

    # training & validation
    best_training(BEST_GENE, EMBED)

    # prediction
    prediction(BEST_GENE, EMBED)
Ejemplo n.º 6
0
ub = [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100]

start_time = time.time()

xopt, fopt = pso(func,
                 lb,
                 ub,
                 ieqcons=[],
                 f_ieqcons=None,
                 args=(),
                 kwargs={},
                 swarmsize=100,
                 omega=0.5,
                 phip=0.5,
                 phig=0.5,
                 maxiter=50000,
                 minstep=1e-8,
                 minfunc=1e-8,
                 debug=False)

elapsed_time = time.time() - start_time

print('Elapsed time: {}\nBest swarm: {}\nBest fitness: {}'.format(
    elapsed_time, xopt, fopt))

# training & validation
best_training(xopt, EMBED)

# prediction
prediction(xopt, EMBED)