示例#1
0
def stat():
    df = read(queries.stats)
    df.columns = [column.upper() for column in df.columns]
    df = df[df.CATEGORY != 'miscellaneous']
    df['CATEGORY'] = [item.upper() for item in df['CATEGORY']]
    df['SUBCATEGORY'] = [item.capitalize() for item in df['SUBCATEGORY']]
    df = df.pivot_table(
        index=['CATEGORY', 'SUBCATEGORY'],
        margins=True,
        margins_name='======= TOTAL =======',  # defaults to 'All'
        aggfunc=sum)
    return render_template(
        'stats.html',
        tables=[df.to_html(table_id='stats', classes='data', header="true")])
示例#2
0
文件: tools.py 项目: stnoah1/mcb
def make_dataset_1(path):
    data = read(queries.select_dataset)
    with open(os.path.join(path, 'label.csv'), 'w') as f:
        for idx, item in tqdm(data.iterrows()):
            filename = "%08d" % item['id'] + '.obj'
            if os.path.isfile(item['file']):
                copyfile(item['file'], os.path.join(path, filename))
                item['subcategory'] = item['subcategory'] if item[
                    'category'] else 'null'
                f.write(','.join([
                    filename, 'null',
                    purify(item['category']),
                    purify(item['subcategory'])
                ]) + '\n')
            else:
                print(filename, item['id'])
示例#3
0
def get_zip(id):
    obj_path = read(queries.select_object_by_id.format(id=id))['file'][0]
    zip_path = obj_path.replace('.obj', 'zip')

    with ZipFile(zip_path, 'w') as zip:
        zip.write(obj_path)

    @after_this_request
    def remove_zipfile(response):
        try:
            os.remove(zip_path)
        except Exception as e:
            print(e)
        return response

    return send_from_directory(os.path.dirname(zip_path),
                               os.path.basename(zip_path))
示例#4
0
文件: tools.py 项目: stnoah1/mcb
def make_dataset_2(path, categories=None):
    data = read(queries.select_dataset)
    if categories:
        data = data[data['category'].isin(categories)]

    eval_portion = 0.1
    test_portion = 0.2

    data['subcategory'] = [
        item if item else data.loc[idx, 'category']
        for idx, item in enumerate(data['subcategory'])
    ]
    subcategories = list(set(data['subcategory'].tolist()))

    f_train = open(os.path.join(path, 'train.csv'), 'w')
    f_test = open(os.path.join(path, 'test.csv'), 'w')
    f_eval = open(os.path.join(path, 'eval.csv'), 'w')

    for subcategory in tqdm(subcategories):
        if subcategory == 'None':
            continue

        subcat_set = data[data['subcategory'] == subcategory]
        subcat_set = shuffle(subcat_set)

        num_subcat_set = len(subcat_set)
        num_subset_eval_set = int(num_subcat_set * eval_portion)
        num_subset_test_set = int(num_subcat_set * test_portion)

        if num_subset_eval_set < 3:
            continue

        for idx, (_, item) in enumerate(subcat_set.iterrows()):
            filename = "%08d" % item['id'] + '.obj'
            item['subcategory'] = purify(item['subcategory'])
            item['category'] = purify(item['category'])

            if idx < num_subset_eval_set:
                data_type = 'eval'
                file = f_eval
            elif idx < num_subset_eval_set + num_subset_test_set:
                data_type = 'test'
                file = f_test
            else:
                data_type = 'train'
                file = f_train

            dst_path = os.path.join(path, data_type, item['subcategory'])
            make_dir(dst_path)
            obj_file = os.path.join(dst_path, filename)
            copyfile(item['file'], obj_file)

            normalized_mesh = normalize_mesh(obj_file)

            with open(obj_file, 'w') as f:
                f.write(normalized_mesh)

            file.write(','.join(
                [filename, 'null', item['category'], item['subcategory']]) +
                       '\n')

    f_test.close()
    f_train.close()
    f_eval.close()
示例#5
0
文件: tools.py 项目: stnoah1/mcb
def get_keywords():
    return read(queries.select_keywords)
示例#6
0
def update_thumbnail():
    agent.read('select * from ')
示例#7
0
def is_model(cadid):
    return not agent.read(
        f"SELECT * from cad_file WHERE source=2 and source_id='{cadid}'").empty
示例#8
0
def get_img(id):
    img_path = read(queries.select_object_by_id.format(id=id))['image'][0]
    return send_from_directory(os.path.dirname(img_path),
                               os.path.basename(img_path))
示例#9
0
def get_obj(id):
    obj_path = read(queries.select_object_by_id.format(id=id))['file'][0]
    return send_from_directory(os.path.dirname(obj_path),
                               os.path.basename(obj_path))
示例#10
0
def get_miscellaneous():
    return read("SELECT * FROM keyword WHERE parent=214")
示例#11
0
def get_subcategory(parent):
    return read(queries.select_category.format(parent=parent))
示例#12
0
def get_dataset():
    return read(queries.select_taxonomy)
示例#13
0
def get_category():
    return read(queries.select_category.format(parent=0))
示例#14
0
def get_unlabeled_imgs():
    return read(queries.select_unlabeled)
示例#15
0
def get_keyword_id(keyword):
    return read(f"SELECT * from keyword where name = '{keyword}'")['id'][0]
示例#16
0
def get_exist_files(output_dir):
    return agent.read(queries.check_trace_part_data.format(file=output_dir))['name'].to_list()
示例#17
0
def get_cad_imgs(label, cad_type):
    return read(queries.select_images.format(label=label, cad_type=cad_type))