# Regularized Instance Embedding for Deep Multi-Instance Learning
## 3 Method
### Instance-Embedding Learning  
Different from fully supervised learning, instance labels in MIL are unknown. Thus, performing instance-level embedding/representation learning is a very challenging task. However, instance-level learning is very important in many applications since it reveals more detailed information and makes MIL approaches more interpretable. As a result, we attempt to solve this challenging problem in this paper.  
In previous MIL methods, instance-embedding learning was usually ignored, while bag embedding was extensively studied. We formulated an instance-embedding-learning framework and propose novel regularized instance embedding as follows.  
Let \(f(x_{ij})\) be an embedding of instance \(\mathbf{x}_{ij}\in\mathbb{R}^{N}\), where \(f:\mathbb{R}^{N}\rightarrow\mathbb{R}^{D}\). Usually, \(f\) is a differential neural network with parameters \(\Theta\). \(\Theta\) contains all the parameters in the multiple layers of the network \(f\). On the basis of instance embedding, there are two styles of prediction functions: instance- and bag-level prediction.  
Instance-level prediction: Let \(h(f(\mathbf{x}_{ij}))\) be an instance classifier, where \(h:\mathbb{R}^{D}\rightarrow\mathbb{R}\) is a binary classifier that predicts the positiveness \(p_{ij}\) of instance \(\mathbf{x}_{ij}\), denoted as follows:  
\[p_{ij}=h(f(\mathbf{x}_{ij})). \tag{3}\]  
Then, instance-level probabilities \([p_{i1},p_{i2},\ldots,p_{im_{i}}]\) are aggregated into bag-level probability using a max operator, denoted as  
\[P_{i}=\max_{j\in[1,m_{i}]}p_{ij}, \tag{4}\]  
where \(m_{i}\) is the total number of instances in the \(i\)th bag, and \(P_{i}\) denotes the probability of the \(i\)th bag being positive. Here, max is chosen rather than mean for the max function, as it is more suitable with the MIL definition.  
Bag-level prediction: This generates bag-level embedding/representation and directly makes bag-level predictions without considering instance-level probabilities. Given an instance-embedding set from the same bag \(f(\mathbf{x}_{ii}),f(\mathbf{x}_{i2}),\ldots,f(\mathbf{x}_{im_{i}})\), we generated the bag embedding using a function denoted as \(F\). There are at least two ways to define \(F\), i.e., using a max or mean pooling function, which are given as follows:  
\[F(f(\mathbf{x}_{ij}|j\in[1,m_{j}]))=\max_{j\in[1,m_{i}]}\left(f(\mathbf{x}_{ ij})\right), \tag{5}\]  
and  
\[F(f(\mathbf{x}_{ij}|j\in[1,m_{j}]))=\text{mean}_{j\in[1,m_{i}]}\left(f( \mathbf{x}_{ij})\right). \tag{6}\]  
Here, max and mean are both elementwise pooling functions that operate on \(D\)-dimensional instance-embedding vectors. After that, a bag predictor is applied to generate bag probability, denoted as follows:  
\[P_{i}=H(F(f(\mathbf{x}_{ij}|j\in[1,m_{j}]))), \tag{7}\]  
where \(H\) is a linear classifier for bag classification. In neural networks, \(H\) can be implemented as a fully connected layer, and its parameters can be optimized together with instance- and bag-level feature-extraction networks in an end-to-end manner.  
The loss function for bag \(X_{i}\) is \(\text{L}=\frac{1}{N}\sum_{i}^{N}\ell(P_{i},Y_{i})\). In this paper, we use cross-entropy loss  
\[\ell(P_{i},Y_{i})=-\{Y_{i}\log(P_{i})+(1-Y_{i})\log(1-P_{i})\}. \tag{8}\]Other loss functions, e.g., Euclidean or softmax loss, can also be utilized. We chose cross-entropy loss following the setting in [5] and the same loss function provides fair comparison in the experiments. For instance- and bag-level predictors, the MIL loss functions of \(X_{i}\) are given, respectively, as follows:  
\[\mathrm{L_{ins}}=\frac{1}{N}\sum_{i=1}^{N}\ell\left(\max_{i\in[1,m_{i}]}h(f( \mathbf{x}_{ij})),Y_{i}\right) \tag{9}\]  
\[\mathrm{L_{bag}}=\frac{1}{N}\sum_{i=1}^{N}\ell\left(H(\max_{j\in[1,m_{i}]}f( \mathbf{x}_{ij})),Y_{i}\right) \tag{10}\]