in web_tool/ModelSessionPyTorchCycle.py [0:0]
def run_large(self,naip_data):
eval_size = 256
batch_size = 128
_,w,h = naip_data.shape
features_out = np.zeros((1,64, w, h))
preds_out = [ np.zeros((w,h,21)) for _ in range(self.num_models) ]
x_coords, y_coords = [],[]
x, y = 0, 0
while x+eval_size<w:
x_coords.append(x)
x += eval_size-10
x_coords.append(w-eval_size)
while y+eval_size<h:
y_coords.append(y)
y += eval_size-10
y_coords.append(h-eval_size)
def evaluate():
inputs = T.from_numpy(batch[:len(batch_coords)]).float().to(self.device)
features = self.core_model(inputs)
preds = [ model(features) for model in self.augment_models ]
for j,c in enumerate(batch_coords):
xj,yj = c
features_out[0,:,xj+5:xj+eval_size-5,yj+5:yj+eval_size-5] = features[j,:,5:-5,5:-5].cpu().numpy()
for m in range(self.num_models):
preds_out[m][xj+5:xj+eval_size-5,yj+5:yj+eval_size-5,:] = np.rollaxis(preds[m][j,1:,5:-5,5:-5].softmax(0).cpu().numpy(), 0, 3)
batch = np.zeros((batch_size,4,eval_size,eval_size))
i = 0
batch_coords = []
for x in x_coords:
for y in y_coords:
batch_coords.append((x,y))
batch[i] = naip_data[:,x:x+eval_size,y:y+eval_size]
i += 1
if i == batch_size:
evaluate()
i = 0
batch_coords = []
if i>0: evaluate()
return features_out, preds_out