예제 #1
0
def create_app(test_config=None):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(SECRET_KEY='dev', DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),)

    if test_config is None:
        app.config.from_pyfile('config.py', silent=True)
    else: 
        app.config.from_mapping(test_config)

    try:
        os.makedires(app.instance_path)
    except OSError:
        pass

    @app.route('/hello')
    def hello():
        return 'Hello World!'

    from . import db
    db.init_app(app)

    return app
예제 #2
0
ttf_list += glob.glob("~/.fonts/*.ttf")  # Ubuntu
print("font count=", len(ttf_list))


# 中央に文字を描画
def draw_text(im, font, text):
    dr = ImageDraw.Draw(im)
    im_sz = np.array(im.size)
    fo_sz = np.array(font.getsize(text))
    xy = (im_sz - fo_sz) / 2
    # print(im_sz, fo_sz)
    dr.text(xy, text, font=font, fill=(255))


# サンプル画像を出力するフォルダ
if not os.path.exists("./image/num"): os.makedires("./image/num")


# 回転させたり拡大したりしてデータを水増しする
def gen_image(base_im, no, font_name):
    for ang in range(-20, 20, 2):
        sub_im = base_im.rotate(ang)
        data = np.asarray(sub_im)
        X.append(data)
        Y.append(no)
        w = image_size
        # 少しずつ拡大する
        for r in range(8, 15, 3):
            size = round((r / 10) * image_size)
            im2 = cv2.resize(data, (size, size), cv2.INTER_AREA)
            data2 = np.asarray(im2)
예제 #3
0
# 중앙에 문자 그리기
def draw_text(im, font, text):
    dr = ImageDraw.Draw(im)
    im_sz = np.array(im.size)
    fo_sz = np.array(font.getsize(text))
    xy = (im_sz - fo_sz) / 2

    print(im_sz, fo_sz)

    dr.text(xy, text, font=font, fill=(255))


# 샘플 이미지를 출력할 폴더
if not os.path.exists('./image/num'):
    os.makedires('./image/num')


# 회전하거나 확대해서 데이터 늘리기
def gen_image(base_im, no, font_name):
    for ang in range(-20, 20, 2):
        sub_im = base_im.rotate(ang)
        data = np.asarray(sub_im)
        X.append(data)
        Y.append(no)
        w = image_size

        # 조금씩 확대하기
        for r in range(8, 15, 3):
            size = round((r / 10) * image_size)
            im2 = cv2.resize(data, (size, size), cv2.INTER_AREA)
예제 #4
0
            trajectory = trajectory_sampler._compute_trajectory(*img.shape)
            latents.append(np.array(trajectory))
            labels.append(label)
            objects.append(img)
            for t in range(args.seq_len):
                sx, sy, _, _ = trajectory[t]
                x[t, sx:sx + img.shape[0], sy:sy + img.shape[1]] += img
        x[x > 255] = 255
        test_videos.append(x.astype(np.uint8))
        test_latents.append(np.array(latents))
        test_labels.append(np.array(labels).astype(np.uint8))
        test_objects.append(np.array(objects))
    test_videos = np.array(test_videos, dtype=np.uint8).transpose(1, 0, 2, 3)
    test_latents = np.array(test_latents).transpose(2, 0, 1, 3)
    test_labels = np.array(test_labels, dtype=np.uint8)
    test_objects = np.array(test_objects)

    # Save results at the given path
    fname = f'mmnist_test_{args.digits}digits_{args.frame_size}.npz'
    if not args.deterministic:
        fname = f's{fname}'
    print(f'Saving testset at {join(args.data_dir, fname)}')
    # Create the directory if needed
    if not os.path.isdir(args.data_dir):
        os.makedires(args.data_dir)
    np.savez_compressed(join(args.data_dir, fname),
                        sequences=test_videos,
                        latents=test_latents,
                        labels=test_labels,
                        digits=test_objects)
예제 #5
0
def create_folder(path):
    if not os.path.exists(path):
        os.makedires(path)
예제 #6
0
sensitivity = args.sensitivity_analysis
year = args.year
bin_size = args.bin_size
country = args.country
max_processes = args.max_processes
SAF_directory = args.SAF_directory
results_path = args.results_path

# Define the path to the scratch directory. This is where logging files will be saved
if 'cluster/home' in os.getcwd():
    scratch_path = os.environ['SCRATCH']
else:
    scratch_path = os.path.join(SAF_directory,'scratch')
# Create a directory if it doesn't already exist
if not os.path.isdir(scratch_path):
    os.makedires(scratch_path)

# Create a results directory if it doesn't already exist
if not os.path.isdir(results_path):
    os.makedires(results_path)

# Create a directory to save plant operation data
if save_operation:
    operations_path = os.path.join(results_path,'operation')
    if not os.path.isdir(operations_path):
        os.mkdir(operations_path)
eval_points_path = os.path.join(results_path,'eval_points.txt')

# Add a logger
sys.path.insert(1, os.path.join(SAF_directory,'scripts','optimization'))
from plant_optimization.utilities import create_logger