In the recent years, researchers proposed a number of successful methods to\nperform out-of-distribution (OOD) detection in deep neural networks (DNNs). So\nfar the scope of the highly accurate methods has been limited to image level\nclassification tasks. However, attempts for generally applicable methods beyond\nclassification did not attain similar performance. In this paper, we address\nthis limitation by proposing a simple yet effective task-agnostic OOD detection\nmethod. We estimate the probability density functions (pdfs) of intermediate\nfeatures of a pre-trained DNN by performing kernel density estimation (KDE) on\nthe training dataset. As direct application of KDE to feature maps is hindered\nby their high dimensionality, we use a set of lower-dimensional marginalized\nKDE models instead of a single high-dimensional one. At test time, we evaluate\nthe pdfs on a test sample and produce a confidence score that indicates the\nsample is OOD. The use of KDE eliminates the need for making simplifying\nassumptions about the underlying feature pdfs and makes the proposed method\ntask-agnostic. We perform extensive experiments on classification tasks using\nbenchmark datasets for OOD detection. Additionally, we perform experiments on\nmedical image segmentation tasks using brain MRI datasets. The results\ndemonstrate that the proposed method consistently achieves high OOD detection\nperformance in both classification and segmentation tasks and improves\nstate-of-the-art in almost all cases. Code is available at\n\\url{https://github.com/eerdil/task_agnostic_ood}\n