jamino30 commited on
Commit
b9f6209
1 Parent(s): 3d5845b

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +1 -1
  2. inference.py +5 -2
app.py CHANGED
@@ -40,7 +40,7 @@ for style_name, style_img_path in style_options.items():
40
  style_features = (model(style_img_512), model(style_img_1024))
41
  cached_style_features[style_name] = style_features
42
 
43
- @spaces.GPU(duration=10)
44
  def run(content_image, style_name, style_strength, output_quality, progress=gr.Progress(track_tqdm=True)):
45
  yield None
46
  img_size = 1024 if output_quality else 512
 
40
  style_features = (model(style_img_512), model(style_img_1024))
41
  cached_style_features[style_name] = style_features
42
 
43
+ @spaces.GPU(duration=15)
44
  def run(content_image, style_name, style_strength, output_quality, progress=gr.Progress(track_tqdm=True)):
45
  yield None
46
  img_size = 1024 if output_quality else 512
inference.py CHANGED
@@ -33,18 +33,21 @@ def inference(
33
  ):
34
  generated_image = content_image.clone().requires_grad_(True)
35
  optimizer = optim_caller([generated_image], lr=lr)
 
36
 
37
  with torch.no_grad():
38
  content_features = model(content_image)
39
 
40
- def closure():
41
  optimizer.zero_grad()
42
  generated_features = model(generated_image)
43
  total_loss = _compute_loss(generated_features, content_features, style_features, alpha, beta)
44
  total_loss.backward()
 
45
  return total_loss
46
 
47
- for _ in tqdm(range(iterations), desc='The magic is happening ✨'):
48
  optimizer.step(closure)
 
49
 
50
  return generated_image
 
33
  ):
34
  generated_image = content_image.clone().requires_grad_(True)
35
  optimizer = optim_caller([generated_image], lr=lr)
36
+ min_losses = [[]] * iterations
37
 
38
  with torch.no_grad():
39
  content_features = model(content_image)
40
 
41
+ def closure(iter):
42
  optimizer.zero_grad()
43
  generated_features = model(generated_image)
44
  total_loss = _compute_loss(generated_features, content_features, style_features, alpha, beta)
45
  total_loss.backward()
46
+ min_losses[iter] = min(min_losses[iter], total_loss.item())
47
  return total_loss
48
 
49
+ for iter in tqdm(range(iterations), desc='The magic is happening ✨'):
50
  optimizer.step(closure)
51
+ print(f'Loss ({iter+1}):', min_losses[iter])
52
 
53
  return generated_image