NeverlandPeter commited on
Commit
6f9f76f
β€’
1 Parent(s): f573f2d
img_demoAE.py CHANGED
@@ -14,8 +14,8 @@ print(f'loading...')
14
 
15
  ########################################################################################################
16
 
17
- model_prefix = 'out-v7c_d8_256-224-13bit-OB32x0.5-226'
18
- input_img = 'kodim19-modified.png'
19
  device = 'cpu' # cpu cuda
20
 
21
  ########################################################################################################
@@ -147,20 +147,22 @@ decoder.load_state_dict(torch.load(f'{model_prefix}-D.pth'))
147
 
148
  ########################################################################################################
149
 
150
- print(f'test image {input_img}...')
151
  img_transform = transforms.Compose([
152
  transforms.PILToTensor(),
153
  transforms.ConvertImageDtype(torch.float),
154
  transforms.Resize((224, 224))
155
  ])
156
 
157
- with torch.no_grad():
158
- img = img_transform(Image.open(input_img)).unsqueeze(0).to(device)
159
- z = encoder(img)
160
- z = ToBinary.apply(z)
161
 
162
- zz = torch.sum(z.squeeze().long() * zpow, dim=0)
163
- print(f'Code shape = {zz.shape}\n{zz.cpu().numpy()}\n')
164
-
165
- out = decoder(z)
166
- vision.utils.save_image(out, f"{input_img.split('.')[0]}-out-13bit.png")
 
 
 
 
 
 
14
 
15
  ########################################################################################################
16
 
17
+ model_prefix = 'out-v7c_d8_256-224-13bit-OB32x0.5-298'
18
+ input_imgs = ['lena.png', 'genshin.png', 'kodim14-modified.png', 'kodim19-modified.png', 'kodim24-modified.png']
19
  device = 'cpu' # cpu cuda
20
 
21
  ########################################################################################################
 
147
 
148
  ########################################################################################################
149
 
 
150
  img_transform = transforms.Compose([
151
  transforms.PILToTensor(),
152
  transforms.ConvertImageDtype(torch.float),
153
  transforms.Resize((224, 224))
154
  ])
155
 
156
+ for input_img in input_imgs:
157
+ print(f'test image {input_img}...')
 
 
158
 
159
+ with torch.no_grad():
160
+ img = img_transform(Image.open(f'img_test/{input_img}')).unsqueeze(0).to(device)
161
+ z = encoder(img)
162
+ z = ToBinary.apply(z)
163
+
164
+ zz = torch.sum(z.squeeze().long() * zpow, dim=0)
165
+ print(f'Code shape = {zz.shape}\n{zz.cpu().numpy()}\n')
166
+
167
+ out = decoder(z)
168
+ vision.utils.save_image(out, f"img_test/{input_img.split('.')[0]}-out-13bit.png")
img_test/genshin-out-13bit.png ADDED
img_test/genshin.png ADDED
img_test/kodim14-modified-out-13bit.png ADDED
kodim14-modified.png β†’ img_test/kodim14-modified.png RENAMED
File without changes
img_test/kodim19-modified-out-13bit.png ADDED
kodim19-modified.png β†’ img_test/kodim19-modified.png RENAMED
File without changes
img_test/kodim24-modified-out-13bit.png ADDED
kodim24-modified.png β†’ img_test/kodim24-modified.png RENAMED
File without changes
img_test/lena-out-13bit.png ADDED
img_test/lena.png ADDED
kodim14-modified-out-13bit.png DELETED
Binary file (102 kB)
 
kodim19-modified-out-13bit.png DELETED
Binary file (88 kB)
 
kodim24-modified-out-13bit.png DELETED
Binary file (98.3 kB)
 
out-v7c_d8_256-224-13bit-OB32x0.5-226-D.pth β†’ out-v7c_d8_256-224-13bit-OB32x0.5-298-D.pth RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:2ef336f14ec15ccaf4c1ef25b96b88ca2ee33e105c6275738eabf519e6aae85c
3
  size 25068760
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:303a913f6a92286082da49f0b469528008f8585ab5d715114d8d9a2d04fa76ef
3
  size 25068760
out-v7c_d8_256-224-13bit-OB32x0.5-226-E.pth β†’ out-v7c_d8_256-224-13bit-OB32x0.5-298-E.pth RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:ce5f83d8f6b35f84a2db5ca29b5502f22e2ce4af7265d18e476e20a79a366406
3
  size 25076297
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ebdfa80d07808a1ea54176e685dc8321257dd1d574caa361b761cdb795356cab
3
  size 25076297