forked from AUTOMATIC1111/stable-diffusion-webui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12f4f47
commit d6fcc6b
Showing
4 changed files
with
54 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
class LearnSchedule: | ||
def __init__(self, learn_rate, max_steps, cur_step=0): | ||
pairs = learn_rate.split(',') | ||
self.rates = [] | ||
self.it = 0 | ||
self.maxit = 0 | ||
for i, pair in enumerate(pairs): | ||
tmp = pair.split(':') | ||
if len(tmp) == 2: | ||
step = int(tmp[1]) | ||
if step > cur_step: | ||
self.rates.append((float(tmp[0]), min(step, max_steps))) | ||
self.maxit += 1 | ||
if step > max_steps: | ||
return | ||
elif step == -1: | ||
self.rates.append((float(tmp[0]), max_steps)) | ||
self.maxit += 1 | ||
return | ||
else: | ||
self.rates.append((float(tmp[0]), max_steps)) | ||
self.maxit += 1 | ||
return | ||
|
||
def __iter__(self): | ||
return self | ||
|
||
def __next__(self): | ||
if self.it < self.maxit: | ||
self.it += 1 | ||
return self.rates[self.it - 1] | ||
else: | ||
raise StopIteration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters