#%%############################################################################ # Load the model ############################################################################### if load_model == True: import_path = os.path.join(os.getcwd(), 'model_export', '2019-06-12_21-46-36') #cnn.load_model_single_file(import_path, 'model_single') cnn.load_model_json(import_path, 'model_json', 'model_weights') #%%############################################################################ # Predict some data ############################################################################### rand_int = np.random.randint(low=0, high=np.size(X_test_data, axis=0)) X_test = X_test_data[rand_int, ] y_test = y_test_data[rand_int, ] y_pred = cnn.predict_sample(X_test) plt_slice = 8 if border == None: plt.imshow(X_test[8, :, :]) else: X_inner = impro.get_inner_slice(X_test, border) plt.imshow(X_inner[plt_slice, :, :]) plt.imshow(y_test[plt_slice, :, :]) plt.imshow(y_pred[plt_slice, :, :]) print('Number of cells (ground truth): ', np.sum(y_test)) print('Number of cells (predicted): ', np.sum(y_pred))
padding='VALID') #p = patches[2,15,6,15,:,:] #plt.imshow(p) #predictions = np.zeros_like(patches, dtype=np.float32) #predictions = np.zeros((patches.shape[0], patches.shape[1], patches.shape[2], stride_z, stride_y, stride_x), dtype=np.float32) predictions = np.zeros((patches.shape[0], patches.shape[1], patches.shape[2], size_z, size_y, size_x), dtype=np.float32) # Predict the density-patches for zslice in range(patches.shape[0]): for row in range(patches.shape[1]): for col in range(patches.shape[2]): X = patches[zslice, row, col, :] prediction = cnn.predict_sample(X) predictions[zslice, row, col, :] = prediction plt.imshow(predictions[8, 5, 7, 12, :, :]) ## Restore the volumes from the patches nuclei = impro.restore_volume(patches=patches, border=(8, 8, 8), output_dim_order='XYZ') density_map = impro.restore_volume(patches=predictions, border=(8, 8, 8), output_dim_order='XYZ') # ## Plot patch #pz = 0