henry000 commited on
Commit
fce8aa7
Β·
1 Parent(s): a51f159

πŸ—ƒοΈ [Update] cahche from diskcache to torch.pt

Browse files
Files changed (2) hide show
  1. requirements.txt +0 -1
  2. yolo/utils/dataloader.py +7 -11
requirements.txt CHANGED
@@ -1,4 +1,3 @@
1
- diskcache
2
  einops
3
  hydra-core
4
  loguru
 
 
1
  einops
2
  hydra-core
3
  loguru
yolo/utils/dataloader.py CHANGED
@@ -2,7 +2,6 @@ import os
2
  from os import path
3
  from typing import List, Tuple, Union
4
 
5
- import diskcache as dc
6
  import hydra
7
  import numpy as np
8
  import torch
@@ -44,18 +43,15 @@ class YoloDataset(Dataset):
44
  Returns:
45
  dict: The loaded data from the cache for the specified phase.
46
  """
47
- cache_path = path.join(dataset_path, ".cache")
48
- cache = dc.Cache(cache_path)
49
- data = cache.get(phase_name)
50
 
51
- if data is None:
52
- logger.info("Generating {} cache", phase_name)
53
  data = self.filter_data(dataset_path, phase_name)
54
- cache[phase_name] = data
55
-
56
- cache.close()
57
- logger.info("πŸ“¦ Loaded {} cache", phase_name)
58
- data = cache[phase_name]
59
  return data
60
 
61
  def filter_data(self, dataset_path: str, phase_name: str) -> list:
 
2
  from os import path
3
  from typing import List, Tuple, Union
4
 
 
5
  import hydra
6
  import numpy as np
7
  import torch
 
43
  Returns:
44
  dict: The loaded data from the cache for the specified phase.
45
  """
46
+ cache_path = path.join(dataset_path, f"{phase_name}.cache")
 
 
47
 
48
+ if not path.isfile(cache_path):
49
+ logger.info("🏭 Generating {} cache", phase_name)
50
  data = self.filter_data(dataset_path, phase_name)
51
+ torch.save(data, cache_path)
52
+ else:
53
+ data = torch.load(cache_path)
54
+ logger.info("πŸ“¦ Loaded {} cache", phase_name)
 
55
  return data
56
 
57
  def filter_data(self, dataset_path: str, phase_name: str) -> list: