text stringlengths 0 93.6k |
|---|
if error == False: |
logging.info(msg) |
else: |
logging.error(msg) |
############################################################################### |
class POINT(object): |
def __init__(self, x, y, z=0.0): |
self.x = x |
self.y = y |
self.z = z |
############################################################################### |
class RECT(object): |
def __init__(self, p1, p2): |
'''Store the top, bottom, left and right values for points |
p1 and p2 are the (corners) in either order |
''' |
self.left = min(p1.x, p2.x) |
self.right = max(p1.x, p2.x) |
self.bottom = min(p1.y, p2.y) |
self.top = max(p1.y, p2.y) |
self.minz = min(p1.z, p2.z) |
self.maxz = max(p1.z, p2.z) |
class MEMORYSTATUSEX(ctypes.Structure): |
_fields_ = [ |
("dwLength", ctypes.c_ulong), |
("dwMemoryLoad", ctypes.c_ulong), |
("ullTotalPhys", ctypes.c_ulonglong), |
("ullAvailPhys", ctypes.c_ulonglong), |
("ullTotalPageFile", ctypes.c_ulonglong), |
("ullAvailPageFile", ctypes.c_ulonglong), |
("ullTotalVirtual", ctypes.c_ulonglong), |
("ullAvailVirtual", ctypes.c_ulonglong), |
("sullAvailExtendedVirtual", ctypes.c_ulonglong), |
] |
def __init__(self): |
# have to initialize this to the size of MEMORYSTATUSEX |
self.dwLength = ctypes.sizeof(self) |
super(MEMORYSTATUSEX, self).__init__() |
################################################################################################### |
if __name__ == "__main__": |
print("lashelper.py copyright GuardianGeomatics Pty Ltd") |
# <FILESEP> |
import caffe |
import numpy as np |
class DiceLoss(caffe.Layer): |
""" |
Compute energy based on dice coefficient. |
""" |
union = None |
intersection = None |
result = None |
gt = None |
def setup(self, bottom, top): |
# check input pair |
if len(bottom) != 2: |
raise Exception("Need two inputs to compute the dice. the result of the softmax and the ground truth.") |
def reshape(self, bottom, top): |
# check input dimensions match |
if bottom[0].count != 2*bottom[1].count: |
print bottom[0].data.shape |
print bottom[1].data.shape |
raise Exception("the dimension of inputs should match") |
# loss output is two scalars (mean and std) |
top[0].reshape(1) |
def forward(self, bottom, top): |
dice = np.zeros(bottom[0].data.shape[0],dtype=np.float32) |
self.union = np.zeros(bottom[0].data.shape[0],dtype=np.float32) |
self.intersection = np.zeros(bottom[0].data.shape[0],dtype=np.float32) |
self.result = np.reshape(np.squeeze(np.argmax(bottom[0].data[...],axis=1)),[bottom[0].data.shape[0],bottom[0].data.shape[2]]) |
self.gt = np.reshape(np.squeeze(bottom[1].data[...]),[bottom[1].data.shape[0],bottom[1].data.shape[2]]) |
self.gt = (self.gt > 0.5).astype(dtype=np.float32) |
self.result = self.result.astype(dtype=np.float32) |
for i in range(0,bottom[0].data.shape[0]): |
# compute dice |
CurrResult = (self.result[i,:]).astype(dtype=np.float32) |
CurrGT = (self.gt[i,:]).astype(dtype=np.float32) |
self.union[i]=(np.sum(CurrResult) + np.sum(CurrGT)) |
self.intersection[i]=(np.sum(CurrResult * CurrGT)) |
dice[i] = 2 * self.intersection[i] / (self.union[i]+0.00001) |
print dice[i] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.