rynmurdock commited on
Commit
f2cdd37
1 Parent(s): 8ec2d8e
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -162,14 +162,14 @@ def predict(
162
 
163
 
164
  # sample a .8 of rated embeddings for some stochasticity, or at least two embeddings.
165
- def get_coeff(embs, ys):
166
- n_to_choose = max(int(len(embs)*.8), 2)
167
- indices = random.sample(range(len(embs)), n_to_choose)
168
 
169
  # we may have just encountered a rare multi-threading diffusers issue (https://github.com/huggingface/diffusers/issues/5749);
170
  # this ends up adding a rating but losing an embedding, it seems.
171
  # let's take off a rating if so to continue without indexing errors.
172
- if len(ys) > len(embs):
173
  print('ys are longer than embs; popping latest rating')
174
  ys.pop(-1)
175
 
@@ -186,9 +186,10 @@ def get_coeff(embs, ys):
186
  if has_0 and has_1:
187
  break
188
 
189
- feature_embs = np.array(torch.cat([embs[i].to('cpu') for i in indices]).to('cpu'))
190
  scaler = preprocessing.StandardScaler().fit(feature_embs)
191
  feature_embs = scaler.transform(feature_embs)
 
192
 
193
  lin_class = LinearSVC(max_iter=50000, dual='auto', class_weight='balanced').fit(feature_embs, np.array([ys[i] for i in indices]))
194
  lin_class.coef_ = torch.tensor(lin_class.coef_, dtype=torch.double)
@@ -232,20 +233,19 @@ def next_image(embs, img_embs, ys, calibrate_prompts):
232
  w = 1.4# if len(embs) % 2 == 0 else 0
233
 
234
  prompt= '' if glob_idx % 2 == 0 else rng_prompt
235
-
236
  prompt, _ = generate(prompt, in_embs=im_s)
237
  print(prompt)
238
  im_emb = autoencoder.embed(prompt)
239
  embs.append(im_emb)
240
 
241
  learn_emb = get_coeff(img_embs, ys)
242
-
243
  img_emb = w * learn_emb.to(dtype=torch.float16)
244
  image, img_emb = predict(prompt, im_emb=img_emb)
245
  img_embs.append(img_emb)
246
 
247
  if len(embs) > 20:
248
  embs.pop(0)
 
249
  ys.pop(0)
250
  return image, embs, img_embs, ys, calibrate_prompts
251
 
 
162
 
163
 
164
  # sample a .8 of rated embeddings for some stochasticity, or at least two embeddings.
165
+ def get_coeff(embs_local, ys):
166
+ n_to_choose = max(int(len(embs_local)*.8), 2)
167
+ indices = random.sample(range(len(embs_local)), n_to_choose)
168
 
169
  # we may have just encountered a rare multi-threading diffusers issue (https://github.com/huggingface/diffusers/issues/5749);
170
  # this ends up adding a rating but losing an embedding, it seems.
171
  # let's take off a rating if so to continue without indexing errors.
172
+ if len(ys) > len(embs_local):
173
  print('ys are longer than embs; popping latest rating')
174
  ys.pop(-1)
175
 
 
186
  if has_0 and has_1:
187
  break
188
 
189
+ feature_embs = np.array(torch.cat([embs_local[i].to('cpu') for i in indices]).to('cpu'))
190
  scaler = preprocessing.StandardScaler().fit(feature_embs)
191
  feature_embs = scaler.transform(feature_embs)
192
+ print(len(feature_embs), len(ys))
193
 
194
  lin_class = LinearSVC(max_iter=50000, dual='auto', class_weight='balanced').fit(feature_embs, np.array([ys[i] for i in indices]))
195
  lin_class.coef_ = torch.tensor(lin_class.coef_, dtype=torch.double)
 
233
  w = 1.4# if len(embs) % 2 == 0 else 0
234
 
235
  prompt= '' if glob_idx % 2 == 0 else rng_prompt
 
236
  prompt, _ = generate(prompt, in_embs=im_s)
237
  print(prompt)
238
  im_emb = autoencoder.embed(prompt)
239
  embs.append(im_emb)
240
 
241
  learn_emb = get_coeff(img_embs, ys)
 
242
  img_emb = w * learn_emb.to(dtype=torch.float16)
243
  image, img_emb = predict(prompt, im_emb=img_emb)
244
  img_embs.append(img_emb)
245
 
246
  if len(embs) > 20:
247
  embs.pop(0)
248
+ img_embs.pop(0)
249
  ys.pop(0)
250
  return image, embs, img_embs, ys, calibrate_prompts
251