preds = np.zeros(shape=(len(B1), NC)) for i in range(num_batches): idx = range(i * batch, (i + 1) * batch) K = A[idx] M, N, O = TD.Patch_gen(K, 29, C) preds[idx] = f_eval(M, N, O) if num_batches * batch < A.shape[0]: tot = num_batches * batch K = A[tot:] M, N, O = TD.Patch_gen(K, 29, C) preds[tot:A.shape[0]] = f_eval(M, N, O) P = np.argmax(preds, axis=-1) MM = np.ravel_multi_index(A.T, np.asarray(B.shape)) print MM.shape print P.shape Final_pred = np.zeros(B1.shape) Final_pred[MM] = P Lab = B1.reshape(Sha) Segs = Final_pred.reshape(Sha) Dice = np.append(Dice, [E.Dice_score(Segs, Lab, 1)]) print Dice io.savemat("/home/xvt131/Biomediq/Results/valitest/%s" % (img[-32:-4]), mdict={ "Seg": Segs, "Lab": Lab })
Sha = B.shape preds = np.zeros(shape=(len(B1), 2)) for i in range(num_batches): idx = range(i * batch, (i + 1) * batch) K = A[idx] M = TD.Patch_gen_three(K, PS, C) M = M.reshape(batch, 1, PS, PS, PS) preds[idx] = f_eval(M) if num_batches * batch < A.shape[0]: tot = num_batches * batch K = A[tot:] M = TD.Patch_gen_three(K, PS, C) M = M.reshape(len(K), 1, PS, PS, PS) preds[tot:A.shape[0]] = f_eval(M) Final_pred = np.argmax(preds, axis=-1) Lab = B1.reshape(Sha) Final_pred = Final_pred.reshape(Sha) Dice = np.append(Dice, [E.Dice_score(Final_pred, Lab, 1)]) print Dice io.savemat("/home/xvt131/Functions/Adhish_copy/3D_strain/%s" % (img[44:]), mdict={ "Seg": Final_pred, "Lab": Lab })
import scipy.io as io import Evaluation as E with np.load("/home/xvt131/Network_adapt/triplanar_Params_WI.npz") as f: param_values = [f['arr_%d' % i] for i in range(len(f.files))] lasagne.layers.set_all_param_values(output, param_values) for img in DP.get_paths("/home/xvt131/Functions/Adhish_copy/Validating-Rand"): A, B, C = TD.Tri_Image_Load(img) B1 = B.reshape(np.prod(B.shape)) batch = 100 num_batches = A.shape[0] / batch Sha = B.shape print Sha TibiaD = [] FemoralD = [] preds = np.zeros(shape = ( len(B1), 2 )) for i in range(num_batches): idx = range(i*batch, (i+1)*batch) K = A[idx] M, N, O, P= TD.Patch_gen(K, 29, C) preds[idx] = f_eval(M,N,O, P) Final_pred = np.argmax(preds, axis = -1) print Final_pred.shape Lab = B1.reshape(Sha) Final_pred = Final_pred.reshape(Sha) TibiaD += [E.Dice_score(Final_pred, Lab, 1)] print TibiaD io.savemat("/home/xvt131/Network_adapt/EvalTri/Seg_%s" %(img[-36:-30]), mdict= {"Seg2_%s" %(img[-36:-30]):Final_pred,"Lab_%s" %(img[-36:-30]):Lab} )
A, B, C = TD.Tri_Image_Load(img) B1 = B.reshape(np.prod(B.shape)) batch = 100 num_batches = A.shape[0] / batch Sha = B.shape TibiaD = [] FemoralD = [] preds = np.zeros(shape=(len(B1), 2)) for i in range(num_batches): idx = range(i * batch, (i + 1) * batch) K = A[idx] M = TD.Patch_gen_three(K, 29, C) M = M.reshape(batch, 1, PS, PS, PS) preds[idx] = f_eval(M) Final_pred = np.argmax(preds, axis=-1) Lab = B1.reshape(Sha) Final_pred = Final_pred.reshape(Sha) TibiaD += [E.Dice_score(Final_pred, Lab, 1)] FemoralD += [E.Dice_score(Final_pred, Lab, 2)] print TibiaD io.savemat("/home/xvt131/Functions/Adhish_copy/EvalThree/Seg_%s" % (img[-36:-30]), mdict={ "Seg_%s" % (img[-36:-30]): Final_pred, "Label_%s" % (img[-36:-30]): Lab })