Spaces:
Runtime error
Runtime error
Download ProposalNetwork/utils/cache.py from AndreasLH/Weakly-Supervised-3DOD: direct link, hf CLI and curl.
- Browser
- Download file 766 Bytes
-
https://huggingface.co/spaces/AndreasLH/Weakly-Supervised-3DOD/resolve/main/ProposalNetwork/utils/cache.py
- Command line
-
hf download hf://spaces/AndreasLH/Weakly-Supervised-3DOD/ProposalNetwork/utils/cache.py
-
curl -L -o cache.py https://huggingface.co/spaces/AndreasLH/Weakly-Supervised-3DOD/resolve/main/ProposalNetwork/utils/cache.py
766 Bytes
| import os | |
| import pickle | |
| def cache(func): | |
| '''caches the output of the function and saves it to a pickle file with name 'cache/{function_name}.pkl', | |
| the next time it is called the result is loaded from the pickle file''' | |
| os.makedirs('cache', exist_ok=True) | |
| file = f'cache/{func.__name__}.pkl' | |
| def wrapper(*args, **kwargs): | |
| if not os.path.exists(file): | |
| var = func(*args, **kwargs) | |
| # do thing | |
| with open(file, "wb") as f: | |
| pickle.dump(var, f) | |
| else: | |
| with open(file, "rb") as f: | |
| var = pickle.load(f) | |
| return var | |
| return wrapper | |
| # example use | |
| if __name__ == '__main__': | |
| def hello(num): | |
| return num + 2 | |
| print(hello(4)) |