improvememory requierement of cache
This commit is contained in:
+21
-11
@@ -96,28 +96,34 @@ class Data:
|
|||||||
class Cache:
|
class Cache:
|
||||||
def __init__(self, folder, neighbourhood, frames, include_neighbours=True):
|
def __init__(self, folder, neighbourhood, frames, include_neighbours=True):
|
||||||
self.cache = dict()
|
self.cache = dict()
|
||||||
|
self.folder = folder
|
||||||
|
self.neighbourhood = neighbourhood
|
||||||
|
self.frames = frames
|
||||||
|
self.include_neighbours = include_neighbours
|
||||||
|
|
||||||
for frame in tqdm.tqdm(frames):
|
|
||||||
|
def read(self, main_id):
|
||||||
|
frames = [frame for frame in self.frames if frame.split()[0] == main_id]
|
||||||
|
for frame in frames:
|
||||||
id = frame.split()[0]
|
id = frame.split()[0]
|
||||||
frame_nr = int(frame.split()[1])
|
|
||||||
garment = frame.split()[2]
|
garment = frame.split()[2]
|
||||||
if id in self.cache.keys():
|
if id in self.cache.keys():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.cache[id] = Data()
|
self.cache[id] = Data()
|
||||||
|
|
||||||
mask = read_garment_mask(folder, id, garment) #np.load(os.path.join(folder, 'mesh_mask', f'{id}.npy')).astype(bool)
|
mask = read_garment_mask(self.folder, id, garment)
|
||||||
|
|
||||||
if include_neighbours:
|
if self.include_neighbours:
|
||||||
k_neighbors = np.argsort(dist[mask, :][:, mask], axis=-1)[:, :neighbourhood] #cloud.get_neighbors(k=neighbourhood)
|
k_neighbors = np.argsort(dist[mask, :][:, mask], axis=-1)[:, :self.neighbourhood]
|
||||||
self.cache[id].k_neighbors = k_neighbors
|
self.cache[id].k_neighbors = k_neighbors
|
||||||
G = tm.graph.vertex_adjacency_graph(m)
|
G = tm.graph.vertex_adjacency_graph(m)
|
||||||
for i in range(v.shape[0]):
|
for i in range(v.shape[0]):
|
||||||
for k in range(25):
|
for k in range(25):
|
||||||
assert nx.has_path(G, i, k_neighbors[i, k]), f'No path between {i} and {k_neighbors[i, k]}'
|
assert nx.has_path(G, i, k_neighbors[i, k]), f'No path between {i} and {k_neighbors[i, k]}'
|
||||||
|
|
||||||
_, faces = _maskFaces(np.zeros((14475,3)), F, mask) #np.load(os.path.join(folder, 'faces', f'{id}.npy'))
|
_, faces = _maskFaces(np.zeros((14475,3)), F, mask)
|
||||||
v = read_posed_garment_frame(folder, id, garment, frame_nr)[mask,:]
|
v = read_posed_garment_frame(folder, id, garment, 0)[mask,:]
|
||||||
m = tm.Trimesh(v, faces, process=False, validate=False)
|
m = tm.Trimesh(v, faces, process=False, validate=False)
|
||||||
outliers = np.array([len(v) for v in m.vertex_neighbors]) == 0
|
outliers = np.array([len(v) for v in m.vertex_neighbors]) == 0
|
||||||
outliers = np.nonzero(outliers)[0]
|
outliers = np.nonzero(outliers)[0]
|
||||||
@@ -130,6 +136,10 @@ class Cache:
|
|||||||
self.cache[id].faces = faces
|
self.cache[id].faces = faces
|
||||||
|
|
||||||
def __getitem__(self, id):
|
def __getitem__(self, id):
|
||||||
|
if id not in self.cache.keys():
|
||||||
|
del self.cache
|
||||||
|
self.cache = dict()
|
||||||
|
self.read(id)
|
||||||
return self.cache[id]
|
return self.cache[id]
|
||||||
|
|
||||||
|
|
||||||
@@ -383,13 +393,13 @@ if __name__ == '__main__':
|
|||||||
start = time.perf_counter()
|
start = time.perf_counter()
|
||||||
|
|
||||||
# generate_curvatures(folder, neighbourhood, frames)
|
# generate_curvatures(folder, neighbourhood, frames)
|
||||||
# curvatures = read_raw_curvatures(folder, frames, neighbourhood)
|
curvatures = read_raw_curvatures(folder, frames, neighbourhood)
|
||||||
# bins = get_bins(curvatures, nr_of_labels)
|
# bins = get_bins(curvatures, nr_of_labels)
|
||||||
# np.save(f'custom_data/{type}_bins{skirt_modifier}_{neighbourhood}.npy', bins)
|
# np.save(f'custom_data/{type}_bins{skirt_modifier}_{neighbourhood}.npy', bins)
|
||||||
# print(bins)
|
# print(bins)
|
||||||
# bins = np.load(f'custom_data/{type}_bins{skirt_modifier}_{neighbourhood}.npy')
|
bins = np.load(f'custom_data/{type}_bins{skirt_modifier}_{neighbourhood}.npy')
|
||||||
# generate_curvature_labels(folder, bins, curvatures, frames, neighbourhood)
|
generate_curvature_labels(folder, bins, curvatures, frames, neighbourhood)
|
||||||
visualize_curvature_labels(folder, frames)
|
# visualize_curvature_labels(folder, frames)
|
||||||
|
|
||||||
print(time.perf_counter() - start)
|
print(time.perf_counter() - start)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user