Bryce commited on
Commit
b325022
·
1 Parent(s): b82c7a5

feature: add HAT super-resolution weights

Browse files
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ unconverted
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ torch
2
+ safetensors
3
+ numpy
src/convert_to_safetensors.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import torch
4
+ from safetensors.torch import save_file
5
+
6
+ project_folder = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
7
+
8
+ def convert_folder_to_safetensors(input_folder: str, output_folder: str):
9
+ """Recursively converts all torch weights to safetensors format and saves them in the same folder structure in output_folder."""
10
+ for root, dirs, files in os.walk(input_folder):
11
+ for file in files:
12
+ if file.endswith(('.pt', '.pth')):
13
+ file_path = os.path.join(root, file)
14
+ relative_path = os.path.relpath(file_path, input_folder)
15
+ output_path = os.path.join(output_folder, relative_path)
16
+ output_path = output_path.rsplit('.', 1)[0] + '.safetensors'
17
+ print(f'Converting {file_path} to {output_path}')
18
+ # Ensure output directory exists
19
+ os.makedirs(os.path.dirname(output_path), exist_ok=True)
20
+
21
+ data = dict(torch.load(file_path))
22
+ if "params" in data:
23
+ data = data["params"]
24
+
25
+ save_file(data, output_path)
26
+
27
+
28
+ if __name__ == "__main__":
29
+ convert_folder_to_safetensors(f'{project_folder}/unconverted', f'{project_folder}/weights')
weights/super-resolution/hat/Real_HAT_GAN_SRx4.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:749d24f14f52368e4073a261a40689f58c2e1b51a7327df4690fafce493e6037
3
+ size 84898436
weights/super-resolution/hat/Real_HAT_GAN_sharper.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4a1810e527ec49e954959fd94f4a2e2dac5e3d8adb324716a6d9f2ba1d7942dc
3
+ size 84898436