#  NeRF-Loc: Transformer-Based Object Localization Within Neural Radiance
Fields

Jiankai Sun1†∗, Yan Xu2∗, Mingyu Ding3, Hongwei Yi4, Jingdong Wang5, Liangjun
Zhang6, Mac Schwager1 ∗ denotes equal contribution. 1 Stanford University
email<EMAIL_ADDRESS>2 The Chinese University of Hong Kong email:
<EMAIL_ADDRESS>The University of Hong Kong 4 Max Planck Institute for
Intelligent Systems, Tübingen, Germany 5 Baidu Inc. 6 Robotics and Autonomous
Driving Lab of Baidu Research, Sunnyvale, CA 94089 USA † work done as an
intern at Baidu Research.

###### Abstract

Neural Radiance Fields (NeRFs) have been successfully used for scene
representation. Recent works have also developed robotic navigation and
manipulation systems using NeRF-based environment representations. As object
localization is the foundation for many robotic applications, to further
unleash the potential of NeRFs in robotic systems, we study _object
localization within a NeRF scene_. We propose a transformer-based framework
NeRF-Loc to extract 3D bounding boxes of objects in NeRF scenes. NeRF-Loc
takes a pre-trained NeRF model and camera view as input, and produces labeled
3D bounding boxes of objects as output. Concretely, we design a pair of
paralleled transformer encoder branches, namely the coarse stream and the fine
stream, to encode both the context and details of target objects. The encoded
features are then fused together with attention layers to alleviate
ambiguities for accurate object localization. We have compared our method with
the conventional transformer-based method and our method achieves better
performance. In addition, we also present the first NeRF samples-based object
localization benchmark NeRFLocBench.

###### Index Terms:

Object Localization, Neural Radiance Fields

##  I Introduction

(a) Architecture

(b) $\times 1.5$

(c) $\times 1$

(d) $\times 0.67$

(e) $\times 0.5$

Figure 1: (a) NeRF-Loc networks process information at multiple scales. The
coarse stream learns to sample the most informative positions in the overview
image, while the fine stream processes the near-field image to extract fine-
grained information. These two streams are connected by an attention fusion
module, after which 3D object localizations are predicted. (b)-(e) shows
images rendered by NeRF from fine to coarse scales. We can see that they
contain different amounts of information.

When a robot explores a novel environment, it needs to perceive the objects
around it and understand the spatial relationships among them, then it can
plan motions to navigate around and manipulate those objects in order to
accomplish its desired goals. Accurately localizing the objects in 3D space
thus becomes a problem of crucial importance for many robotic applications.
The choice of object localization strategy depends on the types of the adopted
perception model and the underlying environment representation. For instance,
some recent works [1, 2, 3, 4] propose to ground the instructions from the
observed 2D camera images, where 2D object localization method [5] is hence
applied. Wada et al. [6] construct 3D maps (represented by point
clouds/voxels) for the purpose of object pose estimation. Then, the 3D CNNs
become a natural choice to process the 3D data. Compared with representing the
scene with a set of 2D images, the reconstructed 3D maps maintain 3D topology
and richer geometric information. This greatly facilitates the robots to
understand the scene and make better decisions.

Figure 2: Framework. Given the camera pose $\mathbf{P}\in SE(3)$ the robot
observes with, we sample a set of query points $(x,y,z)$ along the rays
(emitted from the camera center passing through the camera plane) and then
localize the objects based on the sampled field values. Our framework has two
streams, the fine stream and the coarse stream. They share similar
transformer-based architectures but are in charge of processing different
scopes of NeRF samples. The different sampling scopes (Field of Views) are
controlled by intrinsics $K^{C}$ and $K^{F}$. After the feature encoding, the
cross-attention-based Fusion Module fuses embeddings from the two streams.
Then, the fused features are decoded by the Transformer Decoder. Finally, the
3D bounding boxes and the corresponding categories are predicted by MLP heads.

However, point cloud/voxel-based map representations have significant
limitations. These classic 3D representations generally lack radiance (i.e.,
color and lighting) details, which are essential for object localization, and
the data from these traditional models can be sparse or incomplete. The robot
that relies on point cloud or voxel-based models may thus fail to leverage
realistic structures or appearances of objects as humans do. Recently,
researchers have identified this issue and proposed to represent the
environment with Neural Radiance Fields (NeRFs) [7], and successfully deploy
it in SLAM [8, 9] systems. NeRF is used as a technique for continuous scene
representation where the 3D scene is compressed in feed-forward neural
networks that memorize the density and radiance values of each 3D location.
Compared with the classic representation, NeRF is much more compact and
contains more photo-realistic elements. Nevertheless, we notice that the
conventional object localization methods have difficulties being directly
applied to this scene representation and the object localization in a NeRF has
not been well studied in the literature. On the other hand, from a robot
planning perspective, NeRFs have been used with great success in robotic
motion planning [10] and manipulation [11]. However, motion planning with
implicit neural representations requires that the target location is first
known, rather than randomly specified as in previous work [10]. For example,
the gap between a language instruction like ”go to the chair” and path
planning is to know where the target ”chair” is. Our approach hopes to bridge
this gap.

To fully unleash the potential of NeRFs in robotic applications, we study _3D
object localization in neural fields_ , a non-trivial task that can be seen as
a step towards bridging the gap between robotic perception and
planning/control in environments represented by NeRFs. The challenge mainly
lies in how to effectively exploit the geometric information contained in the
NeRF representation, and in particular, to take advantage of the ease of
scaling with NeRF representation. Specifically, we design a transformer-based
network to directly estimate object localization within a Neural Radiance
Field. To take advantage of the ease of scaling up and down with the NeRF
representation, our framework includes two sub-networks of coarse and fine
streams, which efficiently fuse the information from the wider horizon and the
zoom-in view for comprehensive scene understanding. Intuitively, the coarse
stream perceives a broader view which provides more global contexts to
alleviate the ambiguities, while the fine stream helps to localize the object
at a finer level.

Currently, there is a scarcity of datasets for our task, which needs to
satisfy having both NeRF representations and 3D bounding box annotations.
Objectron [12] is a dataset recently proposed suitable for our task. It
contains consecutive video frames and corresponding camera poses, which can be
used for NeRF training. We build a NeRF object localization benchmark
NeRFLocBench based on Objectron [12] and evaluate our method with it. We show
that our method outperforms the previous baselines.

In summary, our main contributions are as follows:

  * •

We introduce the problem of _object localization in a neural radiance world_ ,
a step towards semantic robotic perception with neural scene representations,
which can be used for downstream tasks such as planning and control.

  * •

We propose NeRF-Loc, a framework for 3D object localization that exploits the
geometric information imposed by neural representations. We also present the
first NeRF samples-based object localization benchmark NeRFLocBench.

  * •

We evaluate our approach extensively and experimental results show that our
approach significantly outperforms existing methods in NeRF object
localization task.

Input: NeRF function $F_{\Theta}$, observation pose $\mathbf{P}$, coarse
intrinsic matrix $K^{C}$ and fine intrinsic matrix $K^{F}$

Output: $J$ object proposals $\\{\hat{\psi}^{j}\\}_{j=1}^{J}$,
$\hat{\psi}^{j}=\\{\hat{B}^{j},\hat{c}^{j}\\}$,
$\hat{B}=\\{x_{i}^{b},y_{i}^{b},z_{i}^{b}\\}_{i=1}^{N_{c}}$ is the coordinates
for each bounding box. $N_{c}$ is the number of corner points. $\hat{c}$ is
the predicted class for each object.

1 $\bm{X}^{C}=F_{\Theta}(\mathbf{P},K^{C})$;

2$\bm{X}^{F}=F_{\Theta}(\mathbf{P},K^{F})$;

3Compute embeddings using coarse encoder and fine encoder (see Equ. (5) and
Equ. (6));

4Fuse embeddings using attention fusion module (see Equ. (7));

5Compute output embeddings using decoder;

6for  _$j\in 1,2,\cdots,J$_ do

7 Predict bounding box instance $\hat{\psi}^{j}=\\{\hat{B}^{j},\hat{p}^{j}\\}$
using prediction head;

8 end for

9Compute optimal matching $\sigma*$ between $\\{\psi^{j}\\}^{J}_{j=1}$ and
$\\{\hat{\psi}^{j}\\}^{J}_{j=1}$ using Hungarian matcher;

10Compute final loss $\mathcal{L}_{H}$ between $\\{\psi^{j}\\}^{J}_{j=1}$ and
$\\{\hat{\psi}^{\sigma*{(j)}}\\}^{J}_{j=1}$;

Backpropagate $\mathcal{L}_{H}$;

Algorithm 1 3D Object Localization on Neural Fields

##  II Related Work

Neural Radiance Field (NeRF). NeRF [7] utilizes an MLP network to predict the
density and color of points in a scene, which allows for differentiable
rendering by tracing rays through the scene and integrating them. Semantic
NeRF [13] extends NeRF to jointly encode 2D semantics with appearance and
geometry. There are also some few-shot NeRFs [14, 15] to perform novel view
synthesis from a sparse set of views. Recently, object-centric NeRFs
investigate how the synthesis process can be controlled at the object-level.
GIRAFFE [16] incorporates a compositional 3D scene representation into the
generative model which leads to more controllable image synthesis. STaR [17]
jointly optimizes the parameters of two Neural Radiance Fields and a set of
rigid poses to decompose a dynamic scene into two constituent parts.
Impressively, Block-NeRF [18] demonstrates the possibility to scale NeRF to
render city-scale scenes spanning multiple blocks. With such great advances in
existing NeRF-related technologies, researchers recently have explored
representing the scene with NeRFs in robotic applications [10, 19, 11].
Following these works, we discuss object localization within the NeRF scenes
in this paper, in the hope of facilitating the downstream robotic applications
with NeRF representations.

Object Localization. Object localization is a key component for robotics
applications including autonomous driving, indoor navigation, and robot
manipulation. Most previous object localization methods can be divided into
three main categories according to the input modality types: point-cloud
based, stereo images based, and monocular image based. The point-cloud based
methods [20, 21, 22, 23] directly acquire the coordinates of the points on the
surfaces of objects in 3D space. These methods generally work on the point
clouds obtained from hardware sensors, e.g., LiDAR. Despite good performance,
the costly depth sensor is not always available for a robotic system. Stereo
image based methods [24] leverage the geometric structures obtained from the
disparities between the stereo image pair. Although stereo-based methods get
rid of the costly depth sensors, a significant length of rig baseline is
required for accurate depth inference, which impedes the application to
compact devices. The monocular methods [25, 26, 27, 28, 29] thus become
popular for object localization in the community given the portable and low-
cost nature. However, none of these methods can be directly applied to NeRF-
based scene representation.

Implicit Representations for Robotics. Adamkiewicz et al. [10] propose a
trajectory planning method that plans full, dynamically feasible trajectories
to avoid collisions with a NeRF environment. Li et al. [19] combine NeRF and
time contrastive learning to learn viewpoint-invariant 3D-aware scene
representations, which enables visuomotor control for challenging manipulation
tasks. Dex-NeRF [11] leverages NeRF’s view-independent learned density, and
performs a transparency-aware depth-rendering to grasp transparent objects.
Lin et al. [30] propose to learn dense object descriptors from NeRFs and use
an optimized NeRF to extract dense correspondences between multiple views of
an object. In contrast to previous work, we find the compact representation of
NeRF (which can be zoomed in and out freely) is particularly useful for 3D
object localization, which can further aid downstream robotics applications
such as navigation and manipulation.

Figure 3: Cross-attention Fusion Module fuses abstraction-levels of coarse and
fine context.

##  III Method

###  III-A Preliminary

NeRF [7] is a differentiable implicit function that represents a continuous 3D
scene. The implicit function is usually implemented with Multi-Layer
Perceptrons (MLPs) $F_{\Theta}:(\bm{x},\bm{d})\rightarrow(\bm{c},\sigma)$,
which maps the 3D location $\bm{x}=(x,y,z)$ and 2D viewing direction
$\bm{d}=(\theta,\phi)$ to an emitted color value $\bm{c}$ and a volume density
value $\sigma$. Based on this representation, the pixel color can be obtained
via volume rendering [31]:

$\begin{split}\hat{C}(\bm{r})=\sum_{k=1}^{K}T_{k}\left(1-\exp\left(-\sigma_{k}(t_{k+1}-t_{k})\right)\right)\bm{c}_{k},\\\
\rm{where}\
T_{k}=\exp\left(-\sum_{k^{\prime}<k}\sigma_{k^{\prime}}(t_{k^{\prime}+1}-t_{k^{\prime}})\right),\end{split}$
(1)

where $\bm{r}(t)=\bm{o}+t\bm{d}$ denotes a ray cast from the camera center
$\bm{o}$ along the direction $\bm{d}$ passing through the rendering pixel.
$T_{k}$ here can be interpreted as the probability that the ray is not
interrupted by before and successfully transmits to point $\bm{r}(t_{k})$.
Similarly, the expected depth $\hat{D}(\bm{r})$ where the camera ray
$\bm{r}(t)=\bm{o}+t\bm{d}$ terminates can be calculated by replacing the color
value $\bm{c}_{k}$ with the sampling distances $t_{k}$:

$\begin{split}\hat{D}(\bm{r})=\sum_{k=1}^{K}T_{k}\left(1-\exp\left(-\sigma_{k}(t_{k+1}-t_{k})\right)\right)t_{k}.\\\
\end{split}$ (2)

###  III-B Problem Formulation

We define the _object localization within Neural Radiance Fields_ task as
follows: Given a pre-constructed NeRF environment $F_{\Theta}$ and an
observation pose $\mathbf{P}\in SE(3)$ inside, we design a transformer network
$G_{\Phi}$ to estimate the 3D bounding box $\hat{B}$ and category $\hat{p}$ of
$J$ objects in the current view:

$\\{(\hat{B}^{j},\hat{p}^{j})\\}_{j=1}^{J}=G_{\Phi}(\mathbf{P};F_{\Theta}).$
(3)

Here, the bounding box $\hat{B}$ is parameterized as its corners
$(\hat{x}^{b},\hat{y}^{b},\hat{z}^{b})$:
$\hat{B}=\\{(\hat{x}^{b}_{i},\hat{y}^{b}_{i},\hat{z}^{b}_{i})\\}_{i=1}^{N_{c}}$
($N_{c}=8$ in our case).

(a)

(b)

(c)

Figure 4:  Qualitative results of NeRF-Loc on the NeRFLocBench validation
split. The detected objects are shown with 3D bounding boxes. Groundtruths are
labeled with red while the predictions from NeRF samples $\hat{\bm{X}}$ are
labeled with blue, the predictions from rendered color images
$\hat{C}(\bm{r})$ are labeled with green, the predictions from rendered depth
maps $\hat{D}(\bm{r})$ are labeled with yellow.

###  III-C NeRF-Loc

Inspired by the effectiveness of multi-view information [32] and the
outstanding performance of transformer-based methods in localization [33, 34],
we designed a transformer-based framework to efficiently utilize information
from multiple views. Fig. 2 shows an overview of the proposed framework. The
pipeline consists of the following steps: 1) Given an observation pose
$\mathbf{P}\in SE(3)$ and the camera intrinsic matrix $\mathbf{K}$, the field
values (i.e. colors and densities) on the eye beams emitted from the camera
center are sampled; 2) The sampled field values are then sent to a
transformer-based coarse encoder and fine encoder for feature extraction. 3)
These encoded features are thereafter fused with an attention fusion module to
complement each other and alleviate ambiguity. 4) Finally, the fused features
are sent to the transformer-based decoder to predict the bounding-box corners
and categories.

####  III-C1 Fine Stream and Coarse Stream

To localize an object in the scene, the network not only should focus on the
object itself but also should leverage the helpful context information around.
Following this intuition, we design two parallel branches, the fine stream and
the coarse stream, to focus on the object details and the context
respectively.

Given an observation pose $\mathbf{P}\in SE(3)$ and the camera intrinsics
$\mathbf{K}=\begin{bmatrix}f&0&p_{x}\\\ 0&f&p_{y}\\\ 0&0&1\end{bmatrix}$, the
rays from the camera center passing through the image plane are chosen for
sampling the radiance field. Specifically, each ray direction $\bm{d}$ is
related to the focal length $f$ and the intersection points $(x,y)$ on the
image plane:

$\bm{d}(x,y,f)=\frac{[x-p_{x},y-p_{y},f]^{T}}{\sqrt{(x-p_{x})^{2}+(y-p_{y})^{2}+f^{2}}}.$
(4)

We apply camera intrinsic matrices with two different focal lengths,
$f/\delta$ and $f$, where $\delta>1$, for the coarse stream and the fine
stream respectively. In our case, we set $\delta=1.5$. In this way, different
sampling scopes are adopted for different streams according to Equ. (4). The
coarse stream essentially has larger field of view while the fine stream has
more detailed views. Empirically, we find the two-stream encoding
significantly improves the localization performance.

After having the sampling rays mentioned above, we sample $N$ equally-spaced
points on each ray and collect the field values $(\mathbf{c},\sigma)$ on these
points. The sampled coarse point sets $\hat{X}^{C}$ and fine point sets
$\hat{X}^{F}$ are modulated by projection layers $l^{C}(\cdot)$ and
$l^{F}(\cdot)$ respectively, and then sent to the coarse and fine transformer
encoders $E^{C}(\cdot)$ and $E^{F}(\cdot)$ for further processing:

$I^{F}=E^{F}(l^{F}(\hat{X}^{F})),$ (5) $I^{C}=E^{C}(l^{C}(\hat{X}^{C})).$ (6)

After the processing, the coarse embeddings $I^{C}$ and fine embeddings
$I^{F}$ are obtained.

TABLE I: Performance comparison of our approach and baselines. Both fine and
coarse information is used for baselines.

Method | mAP@ (%) | Average
---|---|---
IoU | 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9
3DETR [33] | 80.21 | 78.32 | 74.89 | 65.55 | 59.12 | 49.98 | 40.01 | 21.97 | 0.23 | 52.25
NeRF-Loc (Fine-only) | 98.24 | 98.24 | 98.24 | 96.50 | $\bm{91.49}$ | 78.47 | 52.86 | 22.45 | 0.55 | 70.78
NeRF-Loc (Coarse-only) | 95.50 | 95.02 | 94.20 | 92.41 | 88.29 | 75.71 | 47.68 | 20.04 | 0.25 | 67.67
NeRF-Loc | $\bm{99.22}$ | $\bm{98.30}$ | $\bm{98.30}$ | $\bm{97.65}$ | 87.92 | $\bm{80.77}$ | $\bm{60.54}$ | $\bm{23.81}$ | $\bm{1.70}$ | $\bm{72.02}$

####  III-C2 Cross-attention Fusion

To make better use of wide-view information and fine-grained information, we
introduce Cross-attention Fusion, a lateral connections between the coarse
stream and fine stream, to fuse the embeddings from the fine stream and the
coarse stream. The fine stream embeddings $I^{F}$ and coarse stream embeddings
$I^{C}$ are calculated through a lightweight cross-attention head $g(\cdot)$.
Then, the selected information is fused with the original fine-grained
information via skip connection as Equ. (7) shows. We hope that such a design
could learn and benefit from both fine-grained contexts and coarse-grained
contexts at the abstraction level.

$\bar{I}=I^{F}+g(I^{F},I^{C}).$ (7)

####  III-C3 Decoder

The fusion embeddings $\bar{I}$ are passed through the transformer decoder
network $D(\cdot)$, and $J$ localization proposals are obtained from MLP
heads, as expressed by Equ. (8).

$\\{(\hat{B}^{j},\hat{p}^{j})\\}_{j=1}^{J}=D(\bar{I},q),$ (8)

$q$ is the learnable query in the shape of $J$ which is randomly initialized.

(a)

(b)

(c)

Figure 5:  Failure cases on NeRFLocBench validation split. In a) Prediction
error is caused by too vague rendering results. In b) Incomplete object leads
to a failure case, c) The foreground and background look similar, which are
quite difficult for 3D object localization.

###  III-D Loss Functions

From the embeddings output from the decoder, 3D bounding boxes corners are
predicted by MLP regression head $\hat{B}$ and the corresponding categories
$\hat{p}$ are predicted by the MLP classification head. The optimal match is
computed between the augmented ground-truth $\psi^{(j)}$ and prediction
$\hat{\psi}^{(j)}$. We search for the optimal permutation $\sigma*$ among the
set of all permutations, that has the lowest matching cost
$\mathcal{L}_{match}$.

$\sigma*={\arg\min}_{\sigma\in\sum_{J}}\sum_{j=1}^{J}\mathcal{L}_{match}(\psi^{j},\hat{\psi}^{\sigma(j)}).$
(9)

This cost is computed efficiently via the Hungarian algorithm.
$\mathcal{L}_{box}$ is a weighted combination between the IoU loss
$\mathcal{L}_{iou}$ [35] and $\ell_{1}$ loss, weighted by scalar
hyperparameters $\lambda_{iou}$ and $\lambda_{\ell_{1}}$

$\mathcal{L}_{box}=\lambda_{iou}\mathcal{L}_{iou}(B^{j},\hat{B}^{\sigma*(j)})+\lambda_{\ell_{1}}\ell_{1}(B^{j},\hat{B}^{\sigma*(j)}).$
(10)

We use cross-entropy loss $\mathcal{L}_{CE}$ as classification objective. The
Hungarian matching loss $\mathcal{L}_{match}$ is a sum of the classification
and regression loss
$\mathcal{L}_{match}(\psi^{n},\hat{\psi}^{\sigma*(n)})=\mathcal{L}_{box}+\mathcal{L}_{CE}$.
After obtaining the optimal permutation $\sigma*$ based on the lowest
$\mathcal{L}_{match}$, we compute the Hungarian loss $\mathcal{L}_{H}$ for
this optimal matching. $\mathcal{L}_{H}$ over all the matched pairs of
proposals is defined as:

$\mathcal{L}_{H}=\sum_{j=1}^{J}\mathcal{L}_{match}(\psi^{j},\hat{\psi}^{\sigma*(j)}).$
(11)

NeRF-Loc is trained end-to-end, with $\mathcal{L}_{H}$ as its objective. The
full NeRF-Loc learning pipeline is illustrated as Alg. 1.

TABLE II: Ablation study of different modalities. Both fine and coarse
information is used. $\hat{D}(\bm{r})$: rendered depth image,
$\hat{C}(\bm{r})$: rendered color image, $\hat{\bm{X}}$: NeRF raw samples.

Modality | mAP@ (%) | Average
---|---|---
IoU | 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9
$\hat{C}(\bm{r})$ | 81.92 | 74.57 | 68.50 | 60.21 | 49.07 | 31.53 | 15.62 | 5.55 | 0.17 | 43.01
$\hat{D}(\bm{r})$ | 78.51 | 69.66 | 63.82 | 49.23 | 33.74 | 16.69 | 5.49 | 0.45 | 0.00 | 35.28
$\hat{\bm{X}}$ | 99.22 | 98.30 | 98.30 | $\bm{97.65}$ | 87.92 | 80.77 | 60.54 | 23.81 | 1.70 | 72.02
$\hat{\bm{X}}$ \+ $\hat{C}(\bm{r})$ | 98.29 | 98.22 | 97.66 | 96.74 | 93.11 | $\bm{81.32}$ | $\bm{63.33}$ | $\bm{25.92}$ | 0.46 | $\bm{72.78}$
$\hat{\bm{X}}$ \+ $\hat{D}(\bm{r})$ | 97.81 | 96.68 | 95.75 | 93.08 | 84.97 | 75.68 | 51.47 | 19.41 | 1.05 | 68.43
$\hat{C}(\bm{r})$ \+ $\hat{D}(\bm{r})$ | $\bm{99.34}$ | $\bm{99.29}$ | $\bm{98.61}$ | 96.85 | $\bm{94.02}$ | 78.84 | 39.04 | 5.36 | 0.00 | 67.92
$\hat{\bm{X}}$ \+ $\hat{C}(\bm{r})$ \+ $\hat{D}(\bm{r})$ | 97.91 | 97.42 | 94.03 | 90.60 | 86.05 | 78.21 | 57.09 | 25.12 | $\bm{1.84}$ | 69.80

TABLE III: Ablation study of different fusion modules.

Method | mAP@ (%) | Average
---|---|---
IoU | 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9
MLP | 98.95 | 97.99 | 97.99 | $\bm{97.99}$ | $\bm{88.08}$ | 72.04 | 39.79 | 14.13 | 1.45 | 67.60
Attention | $\bm{99.22}$ | $\bm{98.30}$ | $\bm{98.30}$ | 97.65 | 87.92 | $\bm{80.77}$ | $\bm{60.54}$ | $\bm{23.81}$ | $\bm{1.70}$ | $\bm{72.02}$

##  IV Experimental Results

Imagine in the future, we first synthesize a scene with NeRF, after which we
perform robot navigation and manipulation in it, requiring only NeRF
representation and no dependence on other data. This is the application
scenario suitable for the tasks we define. Thus, after the neural radiation
world is built, we are interested in using the learned neural representations
for object localization, without keeping the previous NeRF training data (RGB
images and corresponding camera poses).

We aim to answer the following questions in our experiments: (i) Can we learn
to predict object bounding boxes in Neural Fields? How does NeRF-Loc compare
to existing methods? (ii) Is the raw representation of NeRF better than the
other representations? To answer the first question, we build a challenging
NeRF representation benchmark NeRFLocBench for our task by training NeRF
functions based on a real-world dataset. We show that our approach outperforms
existing approaches. We answer the second question with ablation studies on
different input modalities.

###  IV-A Dataset

To train and test our proposed model, we build a benchmark NeRFLocBench based
on Objectron [12], which is a large-scale dataset consisting of $\sim$15k
continuous videos (about 4M images) with frame-wise annotations. The dataset
is split as $\sim$3k validation and $\sim$12k training videos. Each video has
longer clips averaging a duration of $\sim$15 seconds. Such a long duration
makes it a suitable dataset to train NeRF models and test NeRF-Loc. The
NeRFLocBench is used in all experiments, consisting of coarse and fine-grained
NeRF samples $\hat{X}$ trained using NeRF [7], rendered color image
$\hat{C}(\bm{r})$, rendered depth image $\hat{D}(\bm{r})$ and corresponding 3D
bounding box annotations. We train our model on the training split, compare it
with other methods on validation split and report mean Average Precision
(mAP).

###  IV-B Baselines

Many previous 3D object localization methods rely on CAD models, which are not
required by us. 3DETR [33] is an end-to-end Transformer based object detection
model. We modify it to take the NeRF samples as input and predict the 3D
bounding boxes as output. We evaluate the capacity of our model in 3D object
localization in neural fields and compare it with the baselines and ablations.

###  IV-C Implementation Details

We initialize the Coarse and Fine streams of our network from scratch and
follow an end-to-end training process. We use $\delta=1.5,N_{c}=8,J=100$ in
our experiments. The number of layers of transformer encoder and decoder
$L^{F}_{e}=L^{C}_{e}=L_{d}=4$. For the feature projection layer $l(\cdot)$, we
use 3 layers of MLPs to map the input to 256-dim. Both streams are trained
together for 500 epochs with a batch size of $8$ and a cosine dynamic learning
rate scheduler of $1e-6$ at the start, $5e-4$ as the base learning rate, and
$9$ warm-up epochs with warm-up learning rate of $1e-6$. We train our model
with a machine using NVIDIA TITAN Xp GPU and Intel Xeon CPU.

###  IV-D Evaluating NeRF-Loc on NeRFLocBench

First, we evaluate NeRF-Loc on NeRFLocBench by only taking NeRF samples as
input to verify that we can predict object bounding boxes in neural fields.

In Fig. 4, we visualize some examples of the predicted bounding boxes results
on NeRFLocBench. Our model is able to predict the bounding box of objects with
the correct position. We compare the performance of the NeRF-Loc with 3DETR on
the 3D object localization task in Tab. I. For this evaluation, we report the
performance (mAP) at different IoUs. The comparisons in Tab. I show that our
approach performs better than the previous methods. Our approach is more
effective than other methods when the mAP is at high IoU. Considering the mAP
of high IoUs (higher than 0.6), one can see that object localization on neural
fields benefits a lot from the multi-scale feature. Although our model
outperforms the dual-view baseline using only the fine view, the proposed
Coarse-Fine architecture further improves it by a large margin (from 70.78% to
72.72%).

###  IV-E Ablation Study

####  IV-E1 Modality

We compare multiple modality combinations: (i) NeRF samples $\hat{\bm{X}}$,
(ii) rendered color image $\hat{C}(\bm{r})$, and (iii) rendered depth image
$\hat{D}(\bm{r})$, and the permutation of these three modalities. Both fine
and coarse views are used for all modality combinations. We find that using
only the NeRF samples is better than using the rendered color image or the
rendered depth image individually (see Tab. II). This indicates that using
NeRF samples are more effective than the other two representations and
facilitates faster and better localization. The average mAP of
$\hat{\bm{X}}+\hat{C}(\bm{r})$ is slightly better than using $\hat{\bm{X}}$
only. Considering the time spent on rendering, the obtained NeRF samples are
sufficient for downstream tasks. There is a limited necessity to spend further
time on rendering color or depth maps.

####  IV-E2 Fusion Type

We have also tried MLP fusion layers: simply passing $I^{C}$ and $I^{F}$
through 2 layers of MLPs after stitching them in the last dimension to get
$\bar{I}$. As Tab. III shows, we can see that our cross-attention fusion
module works much better than the MLP fusion module. The difference is more
significant especially when the IoU threshold is high. This is probably due to
the fact that the attention mechanism is more sensitive to fine-grained
features.

##  V Conclusion

We propose the task of object localization in a neural radiance world, which
enables autonomous agents to perceive under implicit representation,
understand where the goal is, and used it for downstream tasks such as
planning and control. We presented NeRF-Loc, a framework for 3D object
localization in neural fields, which can take advantage of the ease of scaling
up and down with the NeRF representation. We introduced the Cross-attention
Fusion to best combine the coarse stream with the fine stream. NeRF-Loc
obtains the best known performance on NeRFLocBench. Our work can be seen as a
step towards the goal of enabling autonomous agents to find the target
location from NeRF world and plan for complex tasks like navigation and
manipulation. In future work, we intend to further explore object localization
tasks in more complex NeRF scenarios with multiple objects.

## References

  * [1] Mohit Shridhar et al.  “Alfred: A benchmark for interpreting grounded instructions for everyday tasks”  In _Proceedings of the IEEE/CVF conference on computer vision and pattern recognition_ , 2020, pp. 10740–10749
  * [2] Kunal Pratap Singh, Suvaansh Bhambri, Byeonghwi Kim, Roozbeh Mottaghi and Jonghyun Choi  “Moca: A modular object-centric approach for interactive instruction following”  In _ICCV_ , 2020
  * [3] Jiankai Sun, De-An Huang, Bo Lu, Yun-Hui Liu, Bolei Zhou and Animesh Garg  “PlaTe: Visually-grounded planning with transformers in procedural tasks”  In _IEEE Robotics and Automation Letters_ 7.2 IEEE, 2022, pp. 4924–4930
  * [4] Alexander Pashevich, Cordelia Schmid and Chen Sun  “Episodic Transformer for Vision-and-Language Navigation”  In _ICCV_ , 2021
  * [5] Kaiming He, Georgia Gkioxari, Piotr Dollár and Ross Girshick  “Mask r-cnn”  In _Proceedings of the IEEE international conference on computer vision_ , 2017, pp. 2961–2969
  * [6] Kentaro Wada, Edgar Sucar, Stephen James, Daniel Lenton and Andrew J Davison  “Morefusion: Multi-object reasoning for 6d pose estimation from volumetric fusion”  In _Proceedings of the IEEE/CVF conference on computer vision and pattern recognition_ , 2020, pp. 14540–14549
  * [7] Ben Mildenhall, Pratul P. Srinivasan, Matthew Tancik, Jonathan T. Barron, Ravi Ramamoorthi and Ren Ng  “NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis”  In _ECCV_ , 2020
  * [8] Edgar Sucar, Shikun Liu, Joseph Ortiz and Andrew J Davison  “iMAP: Implicit mapping and positioning in real-time”  In _Proceedings of the IEEE/CVF International Conference on Computer Vision_ , 2021, pp. 6229–6238
  * [9] Zihan Zhu et al.  “Nice-slam: Neural implicit scalable encoding for slam”  In _Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition_ , 2022, pp. 12786–12796
  * [10] Michal Adamkiewicz et al.  “Vision-only robot navigation in a neural radiance world”  In _IEEE Robotics and Automation Letters_ 7.2 IEEE, 2022, pp. 4606–4613
  * [11] Jeffrey Ichnowski*, Yahav Avigal*, Justin Kerr and Ken Goldberg  “Dex-NeRF: Using a Neural Radiance field to Grasp Transparent Objects”  In _Conference on Robot Learning (CoRL)_ , 2020
  * [12] Adel Ahmadyan, Liangkai Zhang, Artsiom Ablavatski, Jianing Wei and Matthias Grundmann  “Objectron: A Large Scale Dataset of Object-Centric Videos in the Wild with Pose Annotations”  In _Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition_ , 2021
  * [13] Shuaifeng Zhi, Tristan Laidlow, Stefan Leutenegger and Andrew Davison  “In-Place Scene Labelling and Understanding with Implicit Scene Representation”  In _Proceedings of the International Conference on Computer Vision (ICCV)_ , 2021
  * [14] Alex Yu, Vickie Ye, Matthew Tancik and Angjoo Kanazawa  “pixelNeRF: Neural Radiance Fields from One or Few Images”  In _CVPR_ , 2021
  * [15] Konstantinos Rematas, Ricardo Martin-Brualla and Vittorio Ferrari  “Sharf: Shape-conditioned Radiance Fields from a Single View”  In _ICML_ , 2021
  * [16] Michael Niemeyer and Andreas Geiger  “GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields”  In _Proc. IEEE Conf. on Computer Vision and Pattern Recognition (CVPR)_ , 2021
  * [17] Wentao Yuan, Zhaoyang Lv, Tanner Schmidt and Steven Lovegrove  “STaR: Self-supervised Tracking and Reconstruction of Rigid Objects in Motion with Neural Rendering”  In _Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition_ , 2021, pp. 13144–13152
  * [18] Matthew Tancik et al.  “Block-NeRF: Scalable Large Scene Neural View Synthesis”  In _CVPR_ , 2022
  * [19] Yunzhu Li, Shuang Li, Vincent Sitzmann, Pulkit Agrawal and Antonio Torralba  “3D Neural Scene Representations for Visuomotor Control”  In _arXiv preprint arXiv:2107.04004_ , 2021
  * [20] Xiaozhi Chen, Huimin Ma, Ji Wan, Bo Li and Tian Xia  “Multi-view 3d object detection network for autonomous driving”  In _Proceedings of the IEEE conference on Computer Vision and Pattern Recognition_ , 2017, pp. 1907–1915
  * [21] Charles R Qi, Wei Liu, Chenxia Wu, Hao Su and Leonidas J Guibas  “Frustum pointnets for 3d object detection from rgb-d data”  In _Proceedings of the IEEE conference on computer vision and pattern recognition_ , 2018, pp. 918–927
  * [22] Shaoshuai Shi, Xiaogang Wang and Hongsheng Li  “Pointrcnn: 3d object proposal generation and detection from point cloud”  In _Proceedings of the IEEE/CVF conference on computer vision and pattern recognition_ , 2019, pp. 770–779
  * [23] Hongwei Yi et al.  “Segvoxelnet: Exploring semantic context and depth-aware features for 3d vehicle detection from point cloud”  In _2020 IEEE International Conference on Robotics and Automation (ICRA)_ , 2020, pp. 2274–2280  IEEE
  * [24] Xiaozhi Chen, Kaustav Kundu, Yukun Zhu, Huimin Ma, Sanja Fidler and Raquel Urtasun  “3d object proposals using stereo imagery for accurate object class detection”  In _IEEE transactions on pattern analysis and machine intelligence_ 40.5 IEEE, 2017, pp. 1259–1272
  * [25] Yu Xiang, Tanner Schmidt, Venkatraman Narayanan and Dieter Fox  “Posecnn: A convolutional neural network for 6d object pose estimation in cluttered scenes”  In _RSS_ , 2018
  * [26] Zhigang Li, Gu Wang and Xiangyang Ji  “CDPN: Coordinates-Based Disentangled Pose Network for Real-Time RGB-Based 6-DoF Object Pose Estimation”  In _2019 IEEE/CVF International Conference on Computer Vision (ICCV)_ , 2019, pp. 7677–7686  DOI: 10.1109/ICCV.2019.00777
  * [27] Buyu Li, Wanli Ouyang, Lu Sheng, Xingyu Zeng and Xiaogang Wang  “Gs3d: An efficient 3d object detection framework for autonomous driving”  In _Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition_ , 2019, pp. 1019–1028
  * [28] Chen Wang et al.  “DenseFusion: 6D Object Pose Estimation by Iterative Dense Fusion”  In _Computer Vision and Pattern Recognition (CVPR)_ , 2019
  * [29] Mingyu Ding, Zhe Wang, Jiankai Sun, Jianping Shi and Ping Luo  “CamNet: Coarse-to-Fine Retrieval for Camera Re-Localization”  In _Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV)_ , 2019
  * [30] Lin Yen-Chen, Pete Florence, Jonathan T. Barron, Tsung-Yi Lin, Alberto Rodriguez and Phillip Isola  “NeRF-Supervision: Learning Dense Object Descriptors from Neural Radiance Fields”  In _IEEE Conference on Robotics and Automation (ICRA)_ , 2022
  * [31] Marc Levoy  “Efficient ray tracing of volume data”  In _ACM Transactions on Graphics (TOG)_ 9.3 ACM New York, NY, USA, 1990, pp. 245–261
  * [32] Bowen Pan, Jiankai Sun, Ho Yin Tiga Leung, Alex Andonian and Bolei Zhou  “Cross-view semantic segmentation for sensing surroundings”  In _IEEE Robotics and Automation Letters_ 5.3 IEEE, 2020, pp. 4867–4873
  * [33] Ishan Misra, Rohit Girdhar and Armand Joulin  “An End-to-End Transformer Model for 3D Object Detection”  In _ICCV_ , 2021
  * [34] Jiankai Sun, Bolei Zhou, Michael J Black and Arjun Chandrasekaran  “LocATe: End-to-end Localization of Actions in 3D with Transformers”  In _arXiv preprint arXiv:2203.10719_ , 2022
  * [35] Generalized Intersection Over Union  “A Metric and a Loss for Bounding Box Regression”  In _Rezatofighi, N. Tsoi, J. Gwak, A. Sadeghian, I. Reid, S. Savarese//IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), Long Beach, CA, USA_ , 2019, pp. 658–666


Research Article Preprint Version Jana Kierdorf, Remote Sensing Group, Institute of Geodesy and Geoinformation, University of Bonn,d Germany<EMAIL_ADDRESS>European Agriculture Fund for Rural Development with contributions from North-Rhine Westphalia (17-02.12.01 - 10/16 – EP- 0004617925-19-001); Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) (RO4839/7-1 | STO 1087/2-1); DFG under Germany’s Excellence Strategy – EXC 2070 – 390732324

# Reliability Scores from Saliency Map Clusters for Improved Image-based
Harvest-Readiness Prediction in Cauliflower

Jana Kierdorf  Remote Sensing Group, Institute of Geodesy and Geoinformation,
University of Bonn, Germany  Ribana Roscher  Remote Sensing Group, Institute
of Geodesy and Geoinformation, University of Bonn, Germany  Data Science for
Crop Systems, Institute of Bio- and Geosciences, IBG-2: Plant Sciences,
Forschungszentrum Jülich GmbH

###### Abstract

Cauliflower is a hand-harvested crop that must fulfill high-quality standards
in sales making the timing of harvest important. However, accurately
determining harvest-readiness can be challenging due to the cauliflower head
being covered by its canopy. While deep learning enables automated harvest-
readiness estimation, errors can occur due to field-variability and limited
training data. In this paper, we analyze the reliability of a harvest-
readiness classifier with interpretable machine learning. By identifying
clusters of saliency maps, we derive reliability scores for each
classification result using knowledge about the domain and the image
properties. For unseen data, the reliability can be used to (i) inform farmers
to improve their decision-making and (ii) increase the model prediction
accuracy. Using RGB images of single cauliflower plants at different
developmental stages from the GrowliFlower dataset [1], we investigate various
saliency mapping approaches and find that they result in different quality of
reliability scores. With the most suitable interpretation tool, we adjust the
classification result and achieve a 15.72% improvement of the overall accuracy
to 88.14% and a 15.44% improvement of the average class accuracy to 88.52% for
the GrowliFlower dataset.

###### keywords:

Harvest prediction, spectral clustering, reliability, interpretability,
saliency mapping

##  1 Introduction

Accurate harvest time forecasts are crucial for crop quantity and
profitability in agriculture. For cauliflower, high-quality requirements for
sale further complicate this process. To meet these standards, harvesting must
be precisely timed within a short window. Since cauliflower growth is highly
affected by climate, fields planted at different times may be ready for
harvest simultaneously, and plants may develop differently within a single
field. Therefore, it is a common agricultural practice that workers harvest
plants individually by hand at different times. As the cauliflower head is
covered by its canopy, the workers touch the head inside the plant and
estimate the size, making harvesting highly time-consuming.

In digital agriculture, field monitoring is supported by satellite or UAV
imagery [2] to observe plant development throughout the entire growth period.
Machine learning methods increasingly form the basis for analyzing the
acquired data, for example, to classify crop ripeness on a large scale [3] or
to provide detailed predictions about harvest ripeness, the amount of harvest,
or the date of harvest-readiness [4]. Predicting crop traits related to
harvest is of economic benefit to farmers, so the model must be reliable, and
the farmer should be able to have confidence in the model’s decision.

We address the task of harvest-readiness estimation of single cauliflower
plants and aim to derive a reliability score for the model’s output that can
be used to support the farmer in their decision-making process. To reach our
goal, we use saliency mapping to identify image regions that have distinctive
characteristics important for the model decision [5, 6]. We extend the
clustering approach of saliency maps by [7] and combine the maps with
knowledge about our application domain and the image properties to derive
reliability scores of the model’s output. Similar to our approach, some
previous works also aim to improve the model through the integration of
interpretations and explanations [8, 9, 10]. However, these works present ad
hoc frameworks where the interaction between model and explanation is either
learned during training or integrated through human interactions via
retraining. Our work differs in that we propose a framework for deriving a
reliability score for classification predictions that operates post-hoc during
inference time without human interaction. Thus, the system can be applied to
already trained models without changing the model architecture and without the
need for re-training.

The main contributions of this paper are:

  * •

a versatile post-hoc approach to derive intuitive reliability scores without
time-consuming human interaction;

  * •

a use case where the reliability scores are used to improve harvest-readiness
predictions on the GrowliFlower dataset by 15.73% to an overall accuracy of
88.14% and by 15.44% to an average class accuracy of 88.52%.

##  2 Materials and Methods

Figure 1: Our framework. The different numbers represent (1) the
classification step, (2) the saliency mapping step, and (3) the clustering
step of saliency maps with the assignment of reliability to the clusters by
relating the confidence scores of the model to the corresponding saliency
maps. (4) represents the dissemination to the farmer how reliable the model is
while (5) represents the adjustment step, where the predictions of (1) are
improved by using the reliability score of (3).

###  2.1 Framework

We solve the task of estimating the harvest-readiness of single cauliflower
plants with deep learning-based image classification and combine it with an
estimation of the reliability of the classification through clustering of
saliency maps. Fig. 1 shows an overview of the five-step framework.

(1) Classification: In the first step, images are classified into the classes
Ready and Not ready for harvest within three days. We use a ResNet18 network
[11], however, the framework is flexible regarding the classifier.

(2) Saliency mapping: In the second step, we compute saliency maps for
validation and test data post-hoc using the learned classifier. We consider
Gradient-weighted Class Activation Mapping (Grad-CAM) [12], Occlusion
Sensitivity Mapping (OSM) [13], and Local Interpretable Model-Agnostic
Explanations (LIME) [14].

(3) Clustering: We employ spectral clustering to identify groups of saliency
maps computed on the validation data and derive reliability scores. The mean
saliency map per cluster, denoted as prototype, is further analyzed. Test data
can be assigned a reliability score by assigning its saliency map to the
nearest cluster.

(4) Dissemination: The reliability score is intuitively usable due to its
value range between 0 and 1 and is communicated to the user together with the
classification result.

(5) Adjustment: In our use case, the classification results are adjusted based
on the cluster assignments of the saliency maps to determine the final
predicted classes. The decision depends on the summed percentage of false
positives (FP) and false negatives (FN) per cluster. The evaluation of the
classification step provides the assignments to FP and FN.

The framework does not require human interaction and can be applied to
different models. However, human interaction is possible to further improve
the classification results and reliability measures by analyzing and
evaluating the human-understandable clusters of saliency maps.

###  2.2 Data

We use the images of the GrowliFlowerR dataset [1] of Field 2 from the dates
$2021\\_08\\_23$, $2021\\_08\\_25$, $2021\\_08\\_30$, $2021\\_09\\_03$ with
given information about the harvest-readiness within the next three days.
Three days is a compromise between harvest-readiness prediction accuracy and
practicability of data acquisition. We divide the data into the classes Not
ready and Ready. The plants representing both classes show a high similarity
within the same day of acquisition but also between different days. The size
of its head determines the ripeness, however, in most images, the canopy
covers the head. The plant’s stem is centered within the image, but depending
on the plant’s growth, the center of the cauliflower head can vary up to
$20\text{\,}\mathrm{c}\mathrm{m}$ from the stem.

We use the training, validation, and test set as described in [1]. If the
plant shown in an image is already harvested, we exclude the image from the
dataset. This results in a preliminary training set of 541 images, a
validation set of 196 images, and a test set of 194 images. We apply standard
augmentations like flipping and rotation on the training data. For images of
class Not ready, we apply augmentations 50% more often than for images of
class Ready to get a more balanced data distribution. After data augmentation,
the training set contains 6224 images, 2432 of class Not ready, and 3792
images of class Ready.

For each image, we compute corresponding saliency maps. The datasets result in
pairs of image and map. Thus, all target information of the images are also
valid for the corresponding saliency maps.

###  2.3 Classification

We use a ResNet18 [11] architecture with cross-entropy loss, softmax
activation, and two classes as output. We compute the model over 25 epochs and
use an Adam optimizer with a weight decay of 0.0001. The learning rate starts
at 0.0001 and is reduced with a learning rate scheduler with a step size of 5
and factor $\gamma$ of 0.1.

###  2.4 Saliency maps

Saliency maps aim to explain a model’s decision by identifying important
regions in the image. In our case, saliency maps highlight which image regions
are important for predicting the classes Ready and Not ready, allowing
conclusions about the reliability using the prior knowledge that the center of
the image is important for the decision and the background should not play a
role in the harvest-readiness estimation. We consider three local
approaches,that represent the basic principles of saliency mapping, namely a
gradient-based approach, Grad-CAM, and two permutation-based approaches, OSM
and LIME, where LIME differs in that it uses surrogate models, as our focus is
not on the used methods.

Grad-CAM is a gradient-based model-specific method developed by Selveraju et
al. [12] that uses gradient information to determine from which image regions
the convolutional layer takes the information for prediction. The resulting
map depends on the employed layer, where we follow the suggestions of
Selveraju et al. [12] to use the last convolutional layer as it highlights
object-level regions in the image, which are also easier to interpret. Grad-
CAM provides information about the class of interest but no information about
other classes.

The second approach, OSM, is a perturbation-based model-agnostic method
developed by Zeiler et al. [13]. This method evaluates sensitivity towards
occlusion. It uses a sliding window approach with patchsize $p$ and stride $s$
to permute the input by masking patches and, thus, determine the influence of
the occlusion on the predicted model score. A blue pixel in the map indicates
that the score after occlusion is lower than the original score, i.e., this
pixel indicates the presence of the examined class. A red pixel indicates that
the score after occlusion is higher than the original score, indicating a
different class. Note that the smaller $s$, the finer the map’s resolution. In
our experiments, we chose $s=2$ and $p=11$.

Like OSM, the third approach, LIME, is a perturbation-based model-agnostic
method developed by Ribeiro et al. [14]. LIME perturbs the input and computes
the prediction for these perturbed samples with the original model.
Perturbation is applied by changing components in images that are meaningful
to humans, such as superpixels. After perturbation, a local surrogate model is
learned using the perturbed samples. In our work, we use a least squares
linear regression model.

###  2.5 Spectral Clustering

We follow the idea of Lapuschkin et al. [7] by using Spectral Clustering (SC)
introduced by Ng et al. [15] to cluster the resulting saliency maps, which
provides a better understanding of the model decision by taking into account
image features other than RGB. SC involves clustering data based on a
similarity measure derived from a new representation of the data. As
similarity, we chose Gaussian similarity function with a kernel scale of 0.2
based on the Euclidean distance. Before we apply SC on our saliency maps, we
perform principal component analysis on the vectorized data to reduce the
dimensions of the data from 65536 to 50. We decided on a dimension of 50 to
obtain 95% of the variance because there is no unique eigenvalue difference,
i.e. successive eigenvalues have no significant difference. We apply SC to the
validation set and assign the closest cluster IDs to test data using kNN with
$k=5$. For our approach, we set the number of clusters $q=8$ to be
representative and generalizable to other datasets.

###  2.6 Evaluation metrics

To evaluate the adjustment step, the summed percentage of FP and FN is
considered in the calculated clusters $q$. We define this percentage as
reliability score $r_{q}$. The higher the reliability score the more
unreliable is a prediction in a specific cluster. If $r_{q}$ exceeds a
threshold $t$ in cluster $q$ of the validation set, we swap the predicted
class for all samples in cluster $q$ and update the confusion matrix. We
choose $t=75\%$ based on a significant improvement in the validation set’s
accuracy. Threshold $t$ is variable and selectable based on experience. Based
on the updated confusion matrix, we adjust the overall and average class
accuracy. We store the identified clusters for swapping and apply the same to
the test data, followed by updating the test confusion matrix and accuracies.

##  3 Results and Discussion

We run our experiments on an AMD EPYC 7742 64-Core processor and an NVIDIA
A100 for PCIe graphic card with 40 GB hBM2 RAM.

###  3.1 General discussion

Our experiments find that clusters and harvest-readiness classes do not
correlate. This is expected in the case of binary decision-making, where both
classes may end up in the same cluster since they ideally use the same
features. Instead, we focus on whether data within a cluster are correctly
classified or not, which allows conclusions to be drawn about the reliability
of the result. We use the confusion matrix for analysis. To assist the farmer
in making harvesting decisions, we exploit the fact that the saliency maps of
plant images end up in clusters whose classification result is primarily on
the main diagonal of the confusion matrix (TP or TN) and maps that are
associated with incorrect classification results (FP or FN) tend to end up in
separate clusters.

###  3.2 Classification of harvest-readiness

On the validation set, we achieve an overall accuracy of 76.32% and an average
class accuracy of 77.21%. For inference, we achieve an overall accuracy in
classification of 72.41% and an average class accuracy of 73.08%. That means
we are able to predict the harvest-readiness of approx. 3 out of 4 plants
correctly.

###  3.3 Local analysis: Saliency maps of single sample inputs

Figure 2: Resulting saliency maps for the used approaches (b) Grad-CAM, (c)
OSM, and (d) LIME for a RGB input image (a) which is visualized in the maps’
background.

In some of the resulting Grad-CAM maps, a hotspot near the center is
highlighted in the image as shown in Fig. 2 b). In other maps, the highlighted
regions are located near the edges or scattered in the image. It is easy to
analyze which regions have an influence on the model’s decisions since compact
regions are highlighted.

A considerable amount of the OSM results resemble noise regardless of stride
and patchsize for occlusion. Only a minor portion of the results show larger
connected regions that are important for decision, as shown in Fig. 2 c).
These are located in the area of the image that shows, among other things, the
hidden cauliflower head or highlighted leaf regions. Many maps show several
smaller highlighted regions which are difficult to explain because they do not
indicate a unique plant trait. The ability of a simple explanation of the
results varies more than for Grad-CAM.

In LIME maps, we see that the computed superpixels are not able to summarize
pixels to semantically meaningful regions. This could be caused by the
structure or the strong overlap of neighboring plants. Due to this, LIME
saliency maps are difficult to connect to general statements about the
reliability of classification outputs. An example of a sample analyzed by LIME
is shown in Fig. 2 d). We consider LIME not suitable for our application.

Based on the assessment of single saliency maps, we consider Grad-CAM and OSM
to be the most suitable approaches in our framework.

###  3.4 Global analysis: Clustering of saliency maps and reliability
derivation

Fig. 3 show the absolute number of Grad-CAM map assignments of the clustering
results for 8 clusters. A distinction is made between the validation and test
set. The confusion matrix entries are differentiated by color. Our experiments
have shown that 8 clusters produce a good separability between false and
correct predictions. Furthermore, depending on the amount of data, there are
enough data points per cluster to make a reliable statement. Based on the
distribution of validation data in Fig. 3 a), it becomes evident that cluster
5 contains about 95% false predictions, which are equally divided between FP
and FN. This means that over 70% of all FN and FP belong to cluster 5. The
cluster with the second highest proportion of false predictions is cluster 6.
It is worth mentioning that the percentage is only 30%, which corresponds to
only six images. The other clusters contain less than 20% false predictions.
The clustering analysis allows saying with high confidence that samples
assigned to cluster 5 are equivalent to a false prediction and should be
adjusted. The reliability of the classification results of the saliency maps
assigned to this cluster is, therefore, low and should be disseminated to the
farmer. This is underlined in particular by the cluster assignments of the
test data (Fig. 3 b). We observe that 80% of the false predicted test data are
assigned to cluster 5. The proportion of false predictions in the other
clusters is comparable to those within the validation data.

The prototypes of Grad-CAM are shown in Fig. 4. Half of the prototypes
(2,3,7,8) highlight the region in the center of the image. This is the
location in the RGB input images of cauliflower heads covered by leaves, which
are the indicators of cauliflower harvest-readiness. Even though the
cauliflower head is not directly visible in the images, the model identifies
the center of the plant as an essential feature for the classifier to
determine the harvest-readiness. The interpretation of the classification
results is straightforward and understandable for these clusters. The
previously noticed cluster 5 also varies in this representation to the other
clusters. In the image data assigned to the cluster, the classification model
finds no distinctive features for determining the harvest-readiness. The
visualization of the prototypes thus supports the model’s reliability in
addition to the cluster assignment since the visual representation is easier
for the user to understand and interpret.

Figure 3: Clustering of Grad-CAM results. Absolute number of (a) validation
(val) images and (b) test images per cluster. Figure 4: Grad-CAM prototypes
computed by mean saliency map per cluster (1) – (8).

The clustering of the OSM maps shows a uniform distribution of false
predictions in all clusters (Fig. 5 a). The percentage ranges from 10% to 30%.
Based on the OSM cluster results, no statement can be made about the
reliability of the results. The probability that a false prediction occurs in
one of the clusters is similar for all clusters. The cluster assignment of the
test data shows a similar distribution (Fig. 5 b). Only cluster 7 stands out.
It should be noted that the assignment to this cluster corresponds to a single
image only.

The prototypes also suggest no clear trend in terms of what the model uses as
an informative feature in the RGB images (Fig. 6). Clusters 1 and 5 show a
hotspot near the center, which, just like Grad-CAM, suggests that the model is
paying partial attention to the canopy covering the head. Clusters 4, 6, and 8
give a hint of this. Comparing the prototypes of the OSM approach with those
of the Grad-CAM approach, we see that for our scenario, the Grad-CAM approach
results in more interpretable maps than the ones of OSM. Since no clear
differentiation between false and correct prediction can be made in the data
for OSM, the adjustment step introduced in this work is only applied to the
Grad-CAM results. Adjusting the classification results based on the clustering
results would worsen rather than improve the model results.

Figure 5: Clustering of OSM results. Absolute number of (a) validation (val)
images and (b) test images per cluster.

In summary, the combination of saliency map analysis and clustering provides
information about the reliability of classification results. Nevertheless,
some thought should be given to the saliency mapping approach to be used.

Figure 6: OSM prototypes computed by mean saliency map per cluster (1) – (8).

###  3.5 Adjustment of model predictions

With regard to applying the adjustment step to Grad-CAM maps as explained in
Sec. 2.6, we achieve a 13.99% improvement in overall accuracy to 90.31% and a
13.39% improvement in average class accuracy to 90.60% for classification on
the validation set. For inference, we achieve a 15.73% improvement in overall
accuracy to 88.14% and a 15.44% improvement in average class accuracy to
88.52%.

##  4 Conclusion and Future Directions

This work proposes a framework to derive a reliability score for cauliflower
harvest-readiness estimations that operates post-hoc during inference time
without the need for human interaction. Our work combines a ResNet18
classification model with an unsupervised Spectral Clustering approach of
saliency maps to derive a reliability score for classification predictions.
Since the reliability value is in a fixed range between 0 and 1, it is
intuitive and can be provided to the farmer as a decision support. In
addition, the classification predictions can be adjusted, and the accuracy can
be improved. We compare three saliency mapping approaches: Gradient-weighted
Class Activation Mapping, Occlusion Sensitivity Mapping, and Local
Interpretable Model-Agnostic Explanations. Grad-CAM proves to be the most
useful in our scenario.

For our use case, our approach enables the correct harvest-readiness
estimation on GrowliFlowerR, a subset of the GrowliFlower dataset, of approx.
4 out of 5 cauliflowers compared to the state-of-the-art approach ResNet18
which achieves only approx. 3 out of 4 correct predictions. Our framework
offers the advantage of not requiring any interaction with the training
process and it can be applied to already trained models without accessing or
modifying the model architecture. We provide interpretable visualizations and
a reliability score for the model’s decision. Since we only consider false
predictions in our framework, the approach can also be used for reliability
dissemination in multi-class tasks.

## Acknowledgements

This project was funded by the European Agriculture Fund for Rural Development
with contributions from North-Rhine Westphalia (17-02.12.01 - 10/16 –
EP-0004617925-19-001) and by the Deutsche Forschungsgemeinschaft (DFG, German
Research Foundation) (RO 4839/7-1 $|$ STO 1087/2-1). In addition, this work
was supported in part by the DFG under Germany’s Excellence Strategy – EXC
2070 – 390732324.

## References

  * Kierdorf et al. [2022] Kierdorf J, Junker-Frohn LV, Delaney M, Olave MD, Burkart A, Jaenicke H, et al.  GrowliFlower: An image time-series dataset for GROWth analysis of cauLIFLOWER.  J Field Robot 2022;.
  * Fountas et al. [2020] Fountas S, Espejo-García B, Kasimati A, Mylonas N, Darra N.  The Future of Digital Agriculture: Technologies and Opportunities.  IT Professional 2020;22(1):24–28.
  * Lary et al. [2016] Lary DJ, Alavi AH, Gandomi AH, Walker AL.  Machine learning in geosciences and remote sensing.  Geosci Front 2016;7(1):3–10.
  * Klompenburg et al. [2020] Klompenburg TV, Kassahun A, Catal C.  Crop yield prediction using machine learning: A systematic literature review.  Comput Electron Agric 2020;177:105709.
  * Roscher et al. [2020] Roscher R, Bohn B, Duarte MF, Garcke J.  Explain It to Me–Facing Remote Sensing Challenges in the Bio-and Geosciences With Explainable Machine Learning.  ISPRS Ann Photogramm Remote Sens Spat Inf Sci 2020;3:817–824.
  * Brahimi et al. [2018] Brahimi M, Arsenovic M, Laraba S, Sladojevic S, Boukhalfa K, Moussaoui A.  Deep learning for plant diseases: detection and saliency map visualisation.  In: Human and machine learning Springer; 2018.p. 93–117.
  * Lapuschkin et al. [2019] Lapuschkin S, Wäldchen S, Binder A, Montavon G, Samek W, Müller KR.  Unmasking clever hans predictors and assessing what machines really learn.  Nat Commun 2019;10(1):1–8.
  * Weber et al. [2022] Weber L, Lapuschkin S, Binder A, Samek W.  Beyond explaining: Opportunities and challenges of XAI-based model improvement.  Information Fusion 2022;.
  * Schramowski et al. [2020] Schramowski P, Stammer W, Teso S, Brugger A, Herbert F, Shao X, et al.  Making deep neural networks right for the right scientific reasons by interacting with their explanations.  Nat Mach Intell 2020;2(8):476–486.
  * Kim et al. [2022] Kim T, Kim H, Baik K, Choi Y.  Instance-Aware Plant Disease Detection by Utilizing Saliency Map and Self-Supervised Pre-Training.  Agriculture 2022;12(8).  https://www.mdpi.com/2077-0472/12/8/1084.
  * He et al. [2016] He K, Zhang X, Ren S, Sun J.  Deep residual learning for image recognition.  In: Proc. IEEE Conf. Comput. Vis. Pattern Recognit.; 2016. p. 770–778.
  * Selvaraju et al. [2017] Selvaraju RR, Cogswell M, Das A, Vedantam R, Parikh D, Batra D.  Grad-cam: Visual explanations from deep networks via gradient-based localization.  In: Proc. IEEE Int. Conf. Comput. Vis.; 2017. p. 618–626.
  * Zeiler and Fergus [2014] Zeiler MD, Fergus R.  Visualizing and understanding convolutional networks.  In: Comput. Vis. ECCV Springer; 2014. p. 818–833.
  * Ribeiro et al. [2016] Ribeiro MT, Singh D, Guestrin C.  "Why should i trust you?" Explaining the predictions of any classifier.  In: Proc. of the 22nd ACM SIGKDD intern. conf. on KDD; 2016. p. 1135–1144.
  * Ng et al. [2002] Ng AY, Y MIJ, Weiss.  In: Adv. Neural. Inf. Process. Syst.; 2002. p. 849–856.