Example #1
0
def initProcess(params, source, editedSource, difference):
	w, h = source.shape[0], source.shape[1]
	tgtRegion = np.ones(w * h).reshape(w, h)
	srcRegion = np.ones(w * h).reshape(w, h)
	fillFront    = np.ones(w * h).reshape(w, h)
	# Force size_patch to be odd
	assert params['sizePatch'] % 2 == 1, "sizePatch must be odd"
	log.debug('sizePatch:%s'% params['sizePatch'] )
	# Fill targerRegion
	for y in range(h):
		for x in range(w):
			tgtRegion[x,y] = 1 if difference[x,y,:].any() else 0
	nbPoint = np.sum(tgtRegion)
	log.info('nbPoints: %d'%nbPoint)
	# # Initialisation of source_region
	log.debug('tgtRegion.dtype: %s'% tgtRegion.dtype)
	sizeDilate = params['sizeDilate']
	sizeErode = params['sizeErode']
	log.debug('sizeDilate:%s '% sizeDilate)
	structureDilate = np.ones((sizeDilate, sizeDilate))
	structureErode  = np.ones((sizeErode, sizeErode))
	tgtRegionDilated = ndimage.binary_dilation(tgtRegion, structure=structureDilate).astype(tgtRegion.dtype)
	tgtRegionEroded  = ndimage.binary_erosion(tgtRegion , structure=structureErode ).astype(tgtRegion.dtype)
	fillFront = tgtRegionDilated - tgtRegionEroded
	utils.saveOutput(syntheticsDirPath, tgtRegion, 'tgtRegion')
	utils.saveOutput(syntheticsDirPath, tgtRegionDilated, 'tgtRegionDilated')
	utils.saveOutput(syntheticsDirPath, tgtRegionEroded, 'tgtRegionEroded')
	utils.saveOutput(syntheticsDirPath, fillFront, 'fillFront')
	return fillFront, tgtRegion, srcRegion, nbPoint
Example #2
0
def predictFlow(np_arr, model):
    input_data = InputData(np_arr, removePOffset=True, makeDimLess=True)
    input_arr, target_arr = input_data.input, input_data.target 
    input_tr = torch.tensor(input_arr)
    input_batch = input_tr.unsqueeze(0)

    print('Running inference')
    output_batch = model(input_batch.float())
    
    output_tr = output_batch.squeeze(0)
    output_arr = output_tr.detach().numpy()

    print('Saving output')
    saveOutput(output_arr, target_arr)

    return 1
Example #3
0
    net.eval()
    with torch.no_grad():
        for batch_idx, blob in enumerate(valid_loader):
            img = blob['img'].cuda()
            img = img.view(-1, *img.size()[2:])
            # shuf = torch.randperm(len(img))
            shuf = torch.arange(len(img)).view(
                -1, crop_num).t().contiguous().view(-1)
            targ = blob['target'].cuda().repeat(1, crop_num).view(-1, C)[shuf]
            pred = net(img[shuf])
            img = []
            valid_loss.append(lossfunc(pred, targ).cpu().numpy())
            now = batch_idx * batch_size
            valid_pred[now:now + batch_size] = pred
            valid_targ[now:now + batch_size] = targ
            myOutput(batch_idx, len(valid_pred), valid_loss, valid_pred,
                     valid_targ)

    print("epoch:{}/{}".format(epoch, epoches))
    print("Train: ", end='')
    myOutput(-1, len(train_pred), train_loss, train_pred, train_targ)
    print("Valid: ", end='')
    myOutput(-1, len(valid_pred), valid_loss, valid_pred, valid_targ)
    if parallel:
        torch.save(net.module.state_dict(), pt_name.format(epoch))
    else:
        torch.save(net.state_dict(), pt_name.format(epoch))
    saveOutput(save_name, epoch)
    print("Time:", int(time.time() - t), '(s)')
    print("---")
Example #4
0

def saveOutputs(outDir, diff=None):
	if not diff==None:
		plt.imsave(os.path.join(syntheticsDirPath, 'diff.png'), diff)
	return 0

"""Main fonction

This is the main
"""
if __name__ == '__main__':
	logging.info('Start main')
	source, editedSource = getInputs()
	difference = process.run(params, source, editedSource)
	utils.saveOutput(syntheticsDirPath, difference, 'difference')
	logging.info('End main')

##Heart of C code.
# void Pima::run(const char * outputName)
# {
# 	unsigned int IPS(0),JPS(0),IS(0),JS(0),cpt(0);
# 	double Cprec(0.0);
# 	float cpt2(0.9);
# 	CImg<unsigned char> SRC_prec(srcToFillRGB);
# 	SRC_prec.fill(0);
# 	initialize_Pp();
# 	my_display(cpt);
# 	while(nb_points!=0)
# 	{	
# 		cpt++;