def upload_file():
    if request.method == 'POST':
        # 이미지를 현재 시간을 이름으로 저장
        now = time.localtime()
        imageName = str(now.tm_hour) + str(now.tm_min) + str(
            now.tm_sec) + str(".jpg")
        f = request.files['file']
        f.save("./static/uploader/" + imageName)
        print("Saved File : " + "./static/uploader/" + imageName)

        # 예측
        img = preprocess("./static/uploader/" + imageName)  #전처리
        prediction = model.predict(img, verbose=1)
        max_value = max(prediction[0])
        print(max_value)

        if max_value < 0.6:
            return render_template('cannot_find.html',
                                   name="./uploader/" + imageName)
        ###
        ### 여기에 모델이 아직 학습이 안된 경우 제외하는 코드 추가할 예정 ... 20.11.13(신지환)
        ###
        idx = numpy.where(prediction[0] == max_value)[0][0]
        s = Place_Name[str(idx)]
        print(s)  # 결과

        return render_template('search_place.html',
                               name="./uploader/" + imageName,
                               diease=s)
def predict_data(model_path:str,data_path:str,output_path:str):
    with open(model_path,'rb') as f:
        model = pickle.load(f)
    df = pd.read_csv(data_path)
    X,y = preprocess.preprocess(df)
    predictions = predict.predict(model,X)
    pd.DataFrame(predictions).to_csv(output_path,index=False)
    print("Predictions Done")
    print("Output file saved in: %s" % output_path)
def train_model(model_path:str,data_path:str,prov:str='Córdoba'):
    df=pd.read_csv(data_path)
    X,y = preprocess.preprocess(df,prov)
    model,X_test,y_test = train.train_randomforest(X,y)
    predictions = predict.predict(model,X_test)
    mse = mean_squared_error(y_test,predictions)
    r2 = r2_score(y_test,predictions)
    with open(model_path,'wb') as f:
        pickle.dump(model,f)
    print("All Done")
    print("Metrics - MSE: {} R2: {}".format(mse,r2))
    print("Model Saved in: %s" % model_path)
Beispiel #4
0
    def predictEardiease(self, image_path):
        with self.graph.as_default():
            set_session(self.sess)
            # Preprocess : Resize and CLAHE
            img = preprocess(self.directory + "c_" + image_path)

            # Predict
            prediction = self.classificationModel.predict(img, verbose=1)

            # Find Max value's Index
            Accuracy = max(prediction[0])
            idx = np.where(prediction[0] == Accuracy)[0][0]

            return idx, Accuracy
def main(path: str):
    raw_files = []
    for files in glob.glob(path):
        raw_files.append(files)
    df = pd.read_csv(raw_files[0])
    X,y = preprocess.preprocess(df)
    model,X_test,y_test = train.train_randomforest(X,y)
    predictions = predict.predict(model,X_test)
    mse = mean_squared_error(y_test,predictions)
    r2 = r2_score(y_test,predictions)
    print("All Done")
    print("Metrics - MSE: {} R2: {}".format(mse,r2))
    preds = pd.DataFrame(predictions).reset_index().drop(columns='index')
    real = pd.DataFrame(y_test).reset_index().drop(columns='index')
    output = pd.concat([preds,real],axis=1,ignore_index=True)
    output.columns = ['preds','real']
    output.to_csv('output.csv',index=False)
from modules import preprocess, train, predict
import glob
import sys
import pandas as pd

if __name__ == '__main__':
    raw_files = []
    path = '../data/raw/*.csv.gz'
    for files in glob.glob(path):
        raw_files.append(files)
    path = raw_files[0]
    df = pd.read_csv(path)
    df = preprocess.preprocess(df)
    model, X_test, y_test = train.train_randomforest(df)
    predictions, mse, r2 = predict.predict(model, X_test, y_test)
    print("All Done")
    print("Metrics - MSE: {} R2: {}".format(mse, r2))
    preds = pd.DataFrame(predictions).reset_index().drop(columns='index')
    real = pd.DataFrame(y_test).reset_index().drop(columns='index')
    output = pd.concat([preds, real], axis=1, ignore_index=True)
    output.columns = ['preds', 'real']
    output.to_csv('output.csv', index=False)
import time

from tqdm import tqdm
from pathlib import Path

from modules.preprocess import preprocess
from modules import load_data

raw_dir = Path.cwd() / "data/gutenberg_text"
end_dir = Path.cwd() / "data/gutenberg_processed"

# Preprocess whole book list
book_data = load_data.book_data()
numbers = book_data["Catalogue number"].to_list()
books = [book for book in raw_dir.rglob("*.txt") if int(book.stem) in numbers]

start = time.time()
for b in tqdm(books):
    preprocess(b, raw_dir, end_dir, use_id=False)
end = time.time()
print(f"Completed in {round((end - start)/60)} minutes")
Beispiel #8
0
import sys
from modules.preprocess import preprocess
from modules.skipgram import skipgram

if __name__ == '__main__':
    ARGS = sys.argv
    if len(ARGS) == 1 or len(ARGS) > 2:
        print('処理の第一内容を引数に記載してください。')
    elif ARGS[1] == 'preprocess':
        preprocess()
    elif ARGS[1] == 'skipgram':
        skipgram()
    else:
        print('処理の内容を第一引数に記載してください。')