jpc commited on
Commit
f69cd04
·
1 Parent(s): 04f5015

Added input mosaicing

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -5,8 +5,23 @@ import skimage
5
  learn = load_learner('panda-model-1')
6
 
7
  labels = learn.dls.vocab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def predict(img):
9
- img = PILImage.create(img)
10
  pred,pred_idx,probs = learn.predict(img)
11
  return {labels[i]: float(probs[i]) for i in range(len(labels))}
12
 
 
5
  learn = load_learner('panda-model-1')
6
 
7
  labels = learn.dls.vocab
8
+
9
+ def get_crops(img):
10
+ tile_size = 250
11
+ img = np.array(img)
12
+ crop = np.array(img.shape) // tile_size * tile_size; crop
13
+ imgc = img[:crop[0],:crop[1]]
14
+ imgc = imgc.reshape(imgc.shape[0] // tile_size, tile_size, imgc.shape[1] // tile_size, tile_size, 3)
15
+ xs, ys = (imgc.mean(axis=1).mean(axis=2).mean(axis=-1) < 252).nonzero()
16
+ if len(xs) == 0:
17
+ xs, ys = (imgc.mean(axis=1).mean(axis=2).mean(axis=-1)).nonzero()
18
+ # if len(xs) < 2: print("no data in image:", x)
19
+ pidxs = random.choices(list(range(len(xs))), k=36)
20
+ return PILImage.create(imgc[xs[pidxs],:,ys[pidxs],:].reshape(6,6,tile_size,tile_size,3).transpose(0,2,1,3,4).reshape(6*tile_size,6*tile_size,3))
21
+ # return imgc.mean(axis=1).mean(axis=2).mean(axis=-1)
22
+
23
  def predict(img):
24
+ img = get_crops(PILImage.create(img))
25
  pred,pred_idx,probs = learn.predict(img)
26
  return {labels[i]: float(probs[i]) for i in range(len(labels))}
27