In order to create a custom loss that look at values within a sub set (corresponding to faces of a mesh) I need to compute an error base on the value at each vertex of faces. in the corr variable, I have a list of face for the mesh (30k faces) where 3 int value represent a face with the corresponding vertex number. What I did in the custum loss function is : def customLoss(y_true, y_pred): global corr rms2 = 0. for i in range(len(corr)): rms2 += (abs(y_true[corr[0]] - y_pred[corr[0]]) + abs(y_true[corr[1]] - y_pred[corr[1]]) + abs(y_true[corr[2]] - y_pred[corr[2]])) /3 print(i, rms2) return rms2 the idea is to look for each face if the three value are relatively equal. The issue I have is this take a long time to compute. is there a way to speed up the process? for instance I try to access to the y_trueand y_pred with numpy indexation corr = np.array(corr) print(corr.shape) = (29984, 3) but if I try to access in the customloss function y_true[corr] it give me an error ValueError: Shape must be rank 1 but is rank 3 for '{{node customLoss/strided_slice}} = StridedSlice[Index=DT_INT32, T=DT_FLOAT, begin_mask=0, ellipsis_mask=0, end_mask=0, new_axis_mask=0, shrink_axis_mask=1](IteratorGetNext:1, customLoss/strided_slice/stack_1, customLoss/strided_slice/stack_3, customLoss/strided_slice/stack_4)' with input shapes: [?,15003], [1,29984,3], [1,29984,3], [1]. Continue reading...