from flask import send_from_directory, render_template from werkzeug.utils import secure_filename from image_model import ImageModel from datetime import datetime sys.path.append(os.curdir) # カレントファイルをインポートするための設定 UPLOAD_FOLDER = '/tmp/uploads' os.makedirs(UPLOAD_FOLDER, exist_ok=True) ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif']) app = Flask(__name__, static_url_path='/static', static_folder='assets/static') app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER model = ImageModel() model.load('image_model.h5') model.prepare_train_data() def allowed_file(filename): return '.' in filename and \ filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS @app.route('/flask/uploader', methods=['POST']) def upload_file(): # check if the post request has the file part # create a special subfolder for the files uploaded this time # to avoid overwrite
) best_file = f'{config.neural_backbone}_best_fold{fold}_dropout_{config.dropout}.pth' if config.regression: best_file = 'regression_' + best_file log_filename = best_file.replace('.pth', '.txt') model = ImageModel(model_name=config.neural_backbone, device=device, dropout=config.dropout, neurons=0, num_classes=config.num_classes, extras_inputs=[], base_model_pretrained_weights=None) model.load(directory=config.output_dir, filename=best_file) model = model.to(device) if fine_tune: best_file = 'finetune_' + best_file checkpoint_path = os.path.join(config.output_dir, best_file) if os.path.exists(checkpoint_path): print( f"WARNING: TRAINED CHECKPOINT ALREADY EXISTS IN {checkpoint_path}. " f"SKIPPING TRAINING FOR THIS MODEL/FOLD") else: print("Training model!") perform_train(model, device, train_df, val_df, config, best_file, fine_tune)