$terms = get_the_terms(get_the_ID(),'category');
$term_ids = wp_list_pluck($terms,'term_id');
$parents = array_filter(wp_list_pluck($terms,'parent'));
$term_ids_not_parents = array_diff($term_ids, $parents);
$terms_not_parents = array_intersect_key($terms, $term_ids_not_parents);
foreach( $terms_not_parents as $category ) {
echo $category->name;
}