File size: 2,082 Bytes
f7d3a87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import json
import random

from tqdm import tqdm
cad_classes = ['building', 'chair', 'fan', 'lamp', 'table', 'tools', 'vehicle']
dataset = []
for cad_class in cad_classes:
    file_name = f'./dataset/assemblies_15/{cad_class}'
    file_list = os.listdir(file_name)
    for file in tqdm(file_list):
        full_name = os.path.join(file_name, file)
        if 'train_examples.json' not in os.listdir(full_name):
            continue
        else:
            example_path = os.path.join(full_name, 'train_examples.json')
        with open(example_path, 'r', encoding='utf-8') as f:
            data = json.load(f)
        for d in data:
            dataset.append(d)
dataset_path = './dataset/train_dataset.json'
random.shuffle(dataset)
print(len(dataset))
with open(dataset_path, 'w', encoding='utf-8') as f:
    json.dump(dataset, f, ensure_ascii=False, indent=4)
test_dataset = []
val_dataset = []
for cad_class in cad_classes:
    file_name = f'./dataset/assemblies_15/{cad_class}'
    file_list = os.listdir(file_name)
    for file in tqdm(file_list):
        full_name = os.path.join(file_name, file)
        if 'test_examples.json' not in os.listdir(full_name):
            continue
        else:
            example_path = os.path.join(full_name, 'test_examples.json')
        with open(example_path, 'r', encoding='utf-8') as f:
            data = json.load(f)
        for d in data:
            p = random.random()
            if p < 0.01:
                test_dataset.append(d)
            elif p < 0.02:
                val_dataset.append(d)
            else:
                continue
dataset_path = './dataset/test_dataset.json'
print(len(test_dataset))
random.shuffle(test_dataset)
with open(dataset_path, 'w', encoding='utf-8') as f:
    json.dump(test_dataset, f, ensure_ascii=False, indent=4)
dataset_path = './dataset/val_dataset.json'
print(len(val_dataset))
random.shuffle(val_dataset)
with open(dataset_path, 'w', encoding='utf-8') as f:
    json.dump(val_dataset, f, ensure_ascii=False, indent=4)