def computeIoUs(preds, truths):
	"""
	Compute intersection over union for the predicted masks vs ground-truth masks. @preds and @truths must have the same length and both are iterables of numpy matrices of same dimensions.
	"""
	# List to collect IoU for each pair
	IoUs = []
	
	# Iterate over the collections and compute IoUs
	for predicted, truth in zip(preds, truths):
		intersection = predicted * truth
		union = predicted + truth
		
		# Re-adjust union back to [0, 1] scale and return the result.
		union[union == 2] = 1
		IoUs.append(float(sum(intersection.flat)) / (sum(union.flat) or 1))

	return IoUs