Method and apparatus for quantized bayesian deep learning
Patent Information
- Authority / Receiving Office
- EP · EP
- Patent Type
- Applications
- Current Assignee / Owner
- ROBERT BOSCH GMBH
- Filing Date
- 2023-08-28
- Publication Date
- 2026-07-08
AI Technical Summary
Deep Neural Networks (DNNs) face challenges in being deployed on low-power devices due to high computational costs, and quantizing parameters to reduce precision leads to decreased performance.
A stochastic gradient Markov Chain Monte Carlo (SGMCMC) method with approximate Metropolis-Hastings (M-H) corrections is designed for posterior inference of quantized Bayesian neural networks (QBNNs), using a straight-through estimator (STE) and stochastic M-H tests to correct bias caused by discretization.
The method achieves superior accuracy compared to baseline SGMCMC and SGD algorithms on various datasets, including UCI, MNIST, CIFAR, and ImageNet, while maintaining efficiency and correcting quantization biases.
Smart Images

Figure CN2023115225_06032025_PF_FP_ABST
Abstract
Description
METHOD AND APPARATUS FOR QUANTIZED BAYESIAN DEEP LEARNINGFIELD
[0001] The present disclosure relates generally to artificial intelligence (AI) technology, and more particularly, to quantized Bayesian deep learning.BACKGROUND
[0002] Deep Neural Networks (DNNs) have become an important solution to implement artificial intelligence in our daily lives from self-driving cars, smartphones, games, drones, to various other applications. DNNs generally comprise an input layer, an output layer, and several hidden layers. Although neural networks deep may provide advanced performance in many applications, they often come at a high computational cost. Thus, it is impracticable to deploy DNNs into terminal or edge devices with limited power and compute abilities.
[0003] Recently, people have increasing interest in low precision or even binary models credit to their reduced memory size and better efficiency, which enables the models to be run on low-power devices. This may be achieved by quantizing the parameters, such as, the weights between neurons in different layers of a neural network, with low bit-width arithmetic. However, the decrease in precision is inevitably followed by a decrease in performance. How to keep the performance while training a quantized network becomes an important problem.SUMMARY
[0004] The following presents a simplified summary of one or more aspects according to the present disclosure in order to provide a basic understanding of such aspects. This summary is not an extensive overview of all contemplated aspects, and is intended to neither identify key or critical elements of all aspects nor delineate the scope of any or all aspects. Its sole purpose is to present some concepts of one or more aspects in a simplified form as a prelude to the more detailed description that is presented later.
[0005] Generally, a stochastic gradient Markov Chain Monte Carlo (SGMCMC) method with approximate Metropolis-Hastings (M-H) corrections for posterior inference of quantized Bayesian neural networks (QBNNs) is designed in the present disclosure. The disclosed method utilizes straight-through estimator (STE) to propose approximate descending directions for SGMCMC. Then, a stochastic M-H test with further simplifications is utilized to efficiently correct the bias caused by discretization and STE. The disclosed method can guarantee the correct equilibrium distribution even only an STE-approximated direction (rather than a stochastic gradient) is given to SGMCMC. In one aspect, the proposed method may be utilized for posterior inference of binary Bayesian neural networks, which have binarized activations and weights. It is also demonstrated that, the disclosed method can achieve superior accuracy than baseline SGMCMC and SGD algorithms on UCI, MNIST, CIFAR, and ImageNet datasets.
[0006] In an aspect of the disclosure, a method for training a quantized Bayesian Neural Network with Monte Carlo (MC) sampling. The method comprises: initializing a Bayesian Neural Network (BNN) with parameters in an unquantized parameter space, wherein the BNN is used to make an inference with uncertainty based on input images; updating the parameters in the unquantized parameter space during a Metropolis-Hastings (M-H) interval; performing an M-H test to decide whether the updated parameters are acceptable, wherein an accept rate of the M-H test is calculated based on the parameters in the unquantized parameter space; and quantizing the updated parameters into a quantized parameter space with a quantizer.
[0007] In another aspect of the disclosure, an apparatus for training a quantized Bayesian Neural Network with Monte Carlo (MC) sampling is disclosed. The apparatus may comprise a memory and at least one processor coupled to the memory. The at least one processor may be configured to initialize a Bayesian Neural Network (BNN) with parameters in an unquantized parameter space, wherein the BNN is used to make an inference with uncertainty based on input images; update the parameters in the unquantized parameter space during a Metropolis-Hastings (M-H) interval; perform an M-H test to decide whether the updated parameters are acceptable, wherein an accept rate of the M-H test is calculated based on the parameters in the unquantized parameter space; and quantize the updated parameters into a quantized parameter space with a quantizer.
[0008] In another aspect of the disclosure, a computer readable medium storing computer code for training a quantized Bayesian Neural Network with Monte Carlo (MC) sampling is disclosed. The computer code when executed by a processor may cause the processor to a Metropolis-Hastings (M-H) interval; perform an M-H test to decide whether the updated parameters are acceptable, wherein an accept rate of the M- H test is calculated based on the parameters in the unquantized parameter space; and quantize the updated parameters into a quantized parameter space with a quantizer.
[0009] In another aspect of the disclosure, a computer program product for training a quantized Bayesian Neural Network with Monte Carlo (MC) sampling is disclosed. The computer program product may comprise processor executable computer code for initializing a Bayesian Neural Network (BNN) with parameters in an unquantized parameter space, wherein the BNN is used to make an inference with uncertainty based on input images; updating the parameters in the unquantized parameter space during a Metropolis-Hastings (M-H) interval; performing an M-H test to decide whether the updated parameters are acceptable, wherein an accept rate of the M-H test is calculated based on the parameters in the unquantized parameter space; and quantizing the updated parameters into a quantized parameter space with a quantizer.
[0010] Other aspects or variations of the disclosure will become apparent by consideration of the following detailed description and accompanying drawings.BRIEF DESCRIPTION OF THE DRAWINGS
[0011] The following figures depict various embodiments of the present disclosure for purposes of illustration only. One skilled in the art will readily recognize from the following description that alternative embodiments of the methods and structures disclosed herein may be implemented without departing from the spirit and principles of the disclosure described herein.
[0012] FIGs. 1A and 1B illustrate a general neural network and a Bayesian neural network respectively in accordance with one aspect of the present disclosure.
[0013] FIG. 2 illustrates a straight forward M-H method in accordance with one aspect of the present disclosure.
[0014] FIG. 3 illustrates a flow chart of a method for training a quantized Bayesian neural network in accordance with one aspect of the present disclosure.
[0015] FIG. 4 illustrates a block diagram of an apparatus for training a quantized Bayesian neural network in accordance with one aspect of the present disclosure.DETAILED DESCRIPTION
[0016] Before any embodiments of the present disclosure are explained in detail, it is to be understood that the disclosure is not limited in its application to the details of construction and the arrangement of features set forth in the following description. The disclosure is capable of other embodiments and of being practiced or of being carried out in various ways.
[0017] Neural networks are widely used in various applications of the AI technology field, such as, autonomous driving, smart factory, and robot. Bayesian neural network is a popular type of neural network due to its ability to quantify the uncertainty in its predictive output. In a general neural network, the weights between the neurons in different layers of the network take single values. For example, the neural network as shown in Fig. 1A comprises an input layer with neurons x1, x2, …, xc, a first hidden layer with neurons h11, …, h1n, a second hidden layer with neurons h21, …, h2m, and an output layer with neurons y1, y2, …, yc, and the weight between neuron x1 and neuron h11 is a fixed value 0.9, the weight between neuron h21 and neuron y1 is a fixed value 0.6, etc. In a Bayesian neural network (BNN) , the weights take on probability distributions, such as, Gaussian distribution with the parameters of mean μ and variance σ2. For example, the BNN as shown in Fig. 1B similarly comprises an input layer with neurons x1, x2, …, xc, a first hidden layer with neurons h11, …, h1n, a second hidden layer with neurons h21, …, h2m, and an output layer with neurons y1, y2, …, yc, but the weight between neuron x1 and neuron h11 may be a distribution with parameters μ and σ, the weight between neuron h21 and neuron y1 may be a distribution with parameters μ and σ of different values, etc. In this case, the number of parameters of the Bayesian neural network is two times of the number of parameters of a general deep neural network with the same structure (i.e., with same number of layers and neurons in each layer) .
[0018] In other words, Bayesian neural networks offer principled ways to quantify the uncertainty of model parameters and predictions at the expense of increased computational cost. Quantization methods can improve the efficiency of neural network computation by utilizing low bit-width arithmetic. Since the quantizing process brings bias to the updating gradient, Bayesian learning which depends less on the precise back propagation gradient can yield brilliant results. However, the posterior distribution of such quantized Bayesian neural network (QBNN) is not differentiable due to the quantization functions, posing challenges for efficient posterior inference.
[0019] Although Markov Chain Monte Carlo (MCMC) is an important kind of Bayesian learning method, many implementations of it are impracticable for large-scale learning due to the requirement of computations over the whole dataset. Many efforts in decoupling learning from the size of the training dataset have been made, but the M-H correction given by Metropolis et al. and Hastings, which removes bias from the interested Markov chain, is usually not utilized because of it’s expensive computation cost. However, the correction is critical when sampling from a quantized distribution. The M-H corrections have been described in “Equation of State Calculations by Fast Computing Machines” (The Journal of Chemical Physics, vol. 21, no. 6, pp. 1087–1092, 12 2004) and “Monte carlo sampling methods using markov chains and their applications” (Biometrika, vol. 57, pp. 97–109, 1970) , which are incorporated herein for reference.
[0020] For example, many methods for Bayesian learning from large-scale datasets have been proposed. They manage to take advantage of stochastic mini-batch learning while sampling from the Bayesian posterior distribution. For instance, the first-order method Stochastic Gradient Langevin Dynamics (SGLD) proposed by Welling and Teh (see “Bayesian learning via stochastic gradient langevin dynamics” in International Conference on Machine Learning, 2011) and the second-order method SG Hamiltonian Monte Carlo (SGHMC) proposed by Neal et al. (see “Mcmc using hamiltonian dynamics” Handbook of markov chain monte carlo, vol. 2, no. 11, p. 2, 2011) . However, the application of M-H correction is still unacceptable since it requires calculation on the whole dataset.
[0021] As for low precision MCMC method, Low-Precision SGLD proposed by Zhang et al. (see “Low-precision stochastic gradient langevin dynamics” in International Conference on Machine Learning, PMLR, pp. 26 624–26 644, 2022) shows the probability of training low-precision models by Stochastic Gradient MCMC method from scratch. Many low-precision or even binary quantizing methods have been proposed, and the quantizer of Low-Precision SGLD may not be the best.
[0022] In one aspect of this disclosure, a method for binary Bayesian learning for large-scale datasets is proposed. This method may train a binary model along with its full precision parameters. When computing, the full precision parameters are quantized to binary ones. In one embodiment, an adaptive binary method (AdaBin) may be utilized to quantize the parameters of the model. The Adabin quantizer may outperform other binary quantizers, and was proposed by Tu et al. in “Adabin: Improving binary neural networks with adaptive binary sets” (in Computer Vision–ECCV 2022: 17th European Conference, October 23–27, 2022) , which is incorporated herein for reference. Then, the quantized parameters may be updated with the Monte Carlo algorithms (such as, SGHMC, SGMCMC, etc. ) , and the approximate M-H correction may be applied at each end of leapfrog. The correction may also enable the disclosed method to apply different transition kernels when stepping, such as random flip the non-gradient method. After sampling from the desired distribution, an ensemble model can be obtained, which is expected to perform over a single model. This method is also able to get use of the annealing process to get a max a point model, similar to the traditional training methods.
[0023] The above mentioned SGHMC method, Adabin quantizer, and approximate M-H test employed in some preferred embodiments of the present invention will be described below. The method for training a Bayesian neural network for example may be considered as an optimization in the parameter space with a given dataset sampled from the input space where I is the dimension of input space. It is needed to get the distribution and sample from it. By Bayes' theorem,
[0024] where
[0025] For given dataset the distribution is a constant, so we have
[0026] However, it is impracticable to perform back propagation for training the Bayesian neural network directly with the distribution So, some Monte Carlo methods may be used to get samples comply with the distribution, and the samples may be used for remaining operations instead of the distribution.
[0027] Stochastic Gradient Hamiltonian Monte Carlo (SGHMC)
[0028] SGHMC is a type of Monte Carlo methods for sampling. Gibbs canonical distribution gives a probability density function with respect to a potential energy function E (θ) and temperature T :
[0029] Considering similarity, the energy function may be set as
[0030] It is clear that p (θ) , and E (θ) ≥0.
[0031] The parameter θ may be considered as the location of a particle in parameter space Θ, then the potential energy E (θ) is naturally the potential energy of the particle. SGHMC introduces the kinetic energy term with regard to the momentum r and gets the Hamiltonian of the particle
[0032] where m is the mass of the particle, usually set to a convenient constant. Then the Hamiltonian dynamics gives
[0033] To sample the distribution π, the motion of the particle may be simulated. By discreting the time t, we have
[0034] for original (θ0, r0) when t=0 and small ∈>0, and iteratively get (θ, r) at t = 2∈, 3∈, ....
[0035] To handle the differential equations, the leapfrog method may be used. It can provide high quality approximate solution by performing the following steps:
[0036] To enable the particle to explore the parameter space, Gaussian noise may be injected and the momentum r may be modified with a friction term f, changing the Hamiltonian of the system. Now the particle is doing browning motion with friction in a field given by the energy function, and approximate M-H correction may be applied to get unbiased distribution from the changing Hamiltonian.
[0037] Adaptive Binary (AdaBin) Quantization
[0038] Two quantizers Q: Θ→ΘQ, may be used to transform the full bits original weight θ and data x to binary ones Q (θ) and a (x) , where ΘQ is a connected subset of Θ. AdaBin quantization method does this by setting
[0039] where the sign of α is decided by a binary variable. Specifically, for the weight quantizer Q, the quantization may be performed channel by channel. βw may be the channel-wise mean of the full precision parameter, and may be got from minimizing the K-L divergence of the weight before and after quantization, where constant C is the size of the channel. For the activation quantizer a, two learnable parameters αa and βa may be introduced and updated throughout the training. Thus, it can be obtained Q (θ) =βw+αw×Sign (θ-βw)
[0040] where Htanh is hard tanh function used to ensure convergence through the gradient-based updating. By using AdaBin, it is able to preserve much information of full precision data when binarizing as well as accelerating the computation (such as, the convolution operation) by replacing the floating-point multiplication to bit-wise XNOR and BitCount operation.
[0041] Approximate Metropolis-Hastings (M-H) test
[0042] It is an effective strategy to cut down the computational budget of M-H correction to sample more. The approximate M-H test realizes the strategy by reformulating the M-H test as a statistical decision problem. When performing the approximate M-H test, a random subset may be drawn from the dataset time by time, instead of the whole dataset to do an approximate test, considering if a decision to accept or reject should be made with the drawn data. Empirically, the more data is drawn, the more confident a decision can be made. In fact, it is proved that the bias can be controlled by a hyperparameter confidence threshold ∈m (it is called M-H epsilon herein) . When ∈m is set to 0, the approximate M-H test can’t make any decision before all the data is drawn, which is the same as the original M-H method. When ∈m is set to 1, the decision is made instantly when the first mini-batch is tested. To speed up as well as preserve the correction effect, ∈m may be set to 0.2 in a preferred embodiment.
[0043] The pseudocode of the approximate M-H test method is shown below.
[0044] While training a QBNN, posterior sampling of the QBNN may be performed with the above mentioned methods. After applying weight quantizer Q (θ) to SGHMC, the parameter θ is quantized in the front propagation but is not quantized in calculating the prior term in M-H accept rate, so the obtained actual distribution becomes
[0045] which is different from the original distribution
[0046] Since we are interested in the quantized parameter, it may be sampled from the distribution with respect to Q (θ)
[0047] It is noticeable that, the quantized parameter space ΘQ is a proper subset of the original parameter space Θ : denote by θd the parameter of any single channel of any layer, then be any element of θd,
[0048] For example, when the dimension of θd is 3, then On the other hand, ΘQ is a cone, since
[0049] So ΘQ is not a discrete space, thus it is able to consider to sample in this space.
[0050] However, it is challenging to calculate the gradients of the loss function using STE. The quantized parameters cannot be updated towards the gradient descent directions straightly, because this would immediately drag the parameters outside ΘQ. Instead, the present method may update the original parameters in the unquantized space and quantize the parameters again after be updated. However, this may add an extra bias to the update step of the quantized parameters. In order to solve such a problem, the present method may use M-H correction to remove the biases.
[0051] In one example, SGHMC with M-H corrections in quantized space may be performed. In order to balance the performance and efficiency, the present method may make use of the approximate M-H test described above and a further simplification of AMAGOLD proposed by Zhang et al. ( “Amagold: Amortized metropolis adjustment for efficient stochastic gradient mcmc” in International Conference on Artificial Intelligence and Statistics. PMLR, 2020, pp. 2142–2152) . The present method may give up leapfrog and just do M-H correction every T iterations. From the detailed balance property, the accept rate of θt+1 from θt should be
[0052] where
[0053] and rφ is the momentum, ∈ is the step size, σ2 is the momentum variance, β is the friction.
[0054] Fig. 2 illustrates a straight forward M-H method in accordance with one aspect of the present disclosure. For the parameter θt, the quantized parameter Q (θt) lies in the quantized space, such as represented in Fig. 2 (a) with a line in the parameter space Using STE, the gradients in Q (θt) may be obtained and the momentum rt may be updated with the gradients, then θt may be updated with the momentum in unquantized space. Notice that, as shown in Fig. 2 (b) , θt+∈rt≠θt+1, because there exists an injected Gaussian noise l1. Then, as shown in Fig. 2 (c) , the quantizer may be applied to θt+1, and the updated Q (θt+1) may be obtained with extra bias such as l2. Then, an M-H accept rate may be calculated with the q-term
[0055] However, this setting of M-H may spoil the training. On one hand, it focuses on the variance of q (θ∣φ) , 4∈βσ2I. This is a reasonable value when θ, φ ∈ Θ. The less the injected Gaussian noise, the closer θt+1 is expected to be to But when θ, φ∈ΘQ, the problem may arise. When the injected Gaussian noise is small, the bias brought by quantization dominates the distance between and θt+1, thus the obtained accept rate may be almost 0, and the training is unable to continue.
[0056] On the other hand, let Sθ denotes the set of φ such that Q (φ) =θ :
[0057] Look back on the way the weight is quantized, it's clear that for any Sθcould be really "large" . For example, let d=4 and θ= (-1, -1, 1, 1) , we have
[0058] which makes calculating the possibility about Q (θ) impracticable:
[0059] In order to solve such a problem, the present method may pull the parameters back to the unquantized space. Rethinking the problem, after applying weight quantizer to the parameters θ of a BNN, it is obtained a distribution proportional to
[0060] As it is not feasible to sample in the quantized space directly, the present method may pull the likelihood back to the unquantized space. That is, as the θ has to be quantized when predicting, it may be defined p (x∣θ) : =p (x∣Q (θ) )
[0061] Then the sampling can be done in the original (i.e., unquantized) parameter space Θ, with the M-H accept rate below, thereby solving the above mentioned problems.
[0062] For example, the pseudocode of SGHMC with M-H correction in accordance with the present method is shown below.
[0063] FIG. 3 illustrates a flow chart of a method 300 for training a quantized Bayesian neural network with Monte Carlo (MC) sampling in accordance with one aspect of the present disclosure. The method 300 may be implemented by a computer. The MC sampling, comprising SGMCMC, SGHMC, etc., is one kind of methods for Bayesian learning. In block 310, the method 300 may first initialize a Bayesian Neural Network (BNN) with parameters in an unquantized parameter space. The parameters may comprise the parameters of a distribution of the weights of the BNN and / or the parameters of the activation functions in each neuron of the BNN.
[0064] The BNN may be used to make an inference with uncertainty based on input images. The images may be traffic scenarios captured by a camera on an autonomous driving car. The images may be working environment captured by a robot. The images may be point cloud maps captured by radar or LiDAR. The images may also be captured by ultrasonic imager, thermal imager, etc. The images may also be motion images or each frame of a video. In an embodiment of smart manufactory, the BNN may make an inference of whether there is anomaly in the received images, such as, whether the product on the production line is abnormal, and meanwhile provide an uncertainty of the inference such as variances. In an embodiment of autonomous driving, the BNN may make an inference of whether there is a target object in the images, such as, whether there is a pedestrian in front of the car, and meanwhile provide an uncertainty of the inference. The uncertainty provided by a BNN is important especially in the fields of autonomous driving and medical treatment.
[0065] In block 320, the method 300 may update the parameters in the unquantized parameter space during a Metropolis-Hastings (M-H) interval. For example, each M-H interval may comprise 5 iterations. In an embodiment of using SGHMC sampling, the updating may be performed with reference to the above description with regard to the SGHMC. In particular, the parameters may be construed as the location of a particle in the unquantized parameter space, and a momentum of the particle is introduced and may be updated based on the energy of the particle (i.e., the parameters) . As for training a quantized BNN, the momentum may be updated based on quantized parameters, such as in line 7 of the pseudocode of SGHMC with M-H correction shown above, and then, the parameters based on the momentum of the parameters in the unquantized parameter space.
[0066] After each M-H interval is performed, the method 300 may perform an M-H test to decide whether the updated parameters are acceptable in block 330. An accept rate of the M-H test may be calculated based on the parameters in the unquantized parameter space, and whether the updated parameters in an M-H interval will be accepted may be decided based on the accept rate. In one embodiment, the M-H test may be an approximate M-H test based on a confidence threshold. For example, if the confidence threshold is set to 1, the approximate M-H test may make a decision when a mini-batch of dataset is tested; or if the confidence threshold is set to 0, the approximate M-H test may make a decision after all data are drawn from dataset, which is the same as the original M-H algorithm. The dataset are used for training the BNN and may be obtained before initializing the parameters of the BNN in block 310. The approximate M-H test method may cut down the computation cost, and meanwhile the performance is close to the original M-H algorithm. More details about the approximate M-H text may refer to the pseudocode of the approximate M-H test method as shown above.
[0067] In block 340, the method 300 may quantize the updated parameters into a quantized parameter space with a quantizer. The quantizer may be an adaptive binary quantizer. By using an adaptive binary (AdaBin) quantizer, the method 300 is able to preserve much information of full precision data when binarizing, meanwhile accelerating the operations (such as, the convolution operation) by replacing the floating-point multiplication to bit-wise XNOR and BitCount operation.
[0068] The present method combines the advantages of improved efficiency of low-precision neural network and quantifying the uncertainty of model parameters via Bayesian learning. To overcome the optimizing difficulty brought by quantization bias and MCMC sampling, the present method provides a sampling process in quantized parameter space, and corrects the Markov chain with the M-H test while maintaining the efficiency as much as possible. For example, the KL divergence of M-H corrected Markov chains is overall lower than those of uncorrected chains, as the momentum variance decreases.
[0069] In one embodiment, the present method may be implemented with small-scale datasets from UCI collection, using a binarized one hidden layer of 1024 hidden units multilayer perceptron. For each dataset, we randomly cut off a sixth of the whole dataset as the test set, and make the left train set. The batch size may be shifted to adjust the data size. For the present method, the learning rate is fixed at 0.01, and for others including original SGHMC, SGD and SGLD (for comparison) the initial learning rate is set to 0.01 and decays with CosineAnnealing. After comparison, regarding root mean square error (RMSE) for a regression task and error rate for a classification task, the present outperforms SGHMC, SGD, and SGLD on most datasets of UCI collection.
[0070] In another embodiment, a binarized ResNet-18 model may be trained with the present method, as well as SGHMC, SGLD and SGD methods for comparison on the MNIST dataset. The initial learning rate may be set to 0.1. For SGHMC, SGLD and SGD, the learning rate decays with CosineAnnealing and for the present method it is fixed. Training batch size may be set to 200, and M-H correction may be done every 10 iterations. Since the present method costs about half of the time more than SGLD, SGD and SGHMC per epoch due to the M-H correction, so SGLD, SGD and SGHMC are trained more epochs for the sake of fairness. The models trained with the present method and SGLD use the models trained by SGHMC for 20 epochs as the initialization. The training of each method is done 3 times repeatedly. The results are shown in Table 1 below with the present method noted as M-H. It can be seen that the present method provides higher accuracy than the other methods.
[0071] Table 1
[0072] In another embodiment, a binarized ResNet-18 model may be trained with the present method, as well as SGHMC, SGLD and SGD methods for comparison on the CIFAR 10 dataset. The setting of the learning rate may be the same as that on MNIST. Training batch size may be set to 100, and M-H correction may be done every 10 iterations. The 140-epochs M-H (refer to the present method) trained model uses a model trained by SGD for 100 epochs as the initialization. The advantage of the present method may be observed in relatively short time training in Table 2. A model is also trained with the present method for 30 epochs using a model trained by SGD for 400 epochs as the initialization. The result shows the present method improves about 0.5%accuracy over the original SGD.
[0073] Table 2
[0074] FIG. 4 illustrates a block diagram of an apparatus 400 for training a quantized Bayesian neural network in accordance with one aspect of the present disclosure. The apparatus 400 for training a quantized Bayesian Neural Network with Monte Carlo (MC) sampling may comprise a memory 410 and at least one processor 420. The processor 420 may be coupled to the memory 410 and configured to perform the method 300 described above with reference to FIG. 3. The processor 420 may be a general-purpose processor, or may also be implemented as a combination of computing devices, e.g., a combination of a DSP and a microprocessor, multiple microprocessors, one or more microprocessors in conjunction with a DSP core, or any other such configuration. The memory 410 may store the input data, output data, data generated by processor 420, and / or instructions executed by processor 420.
[0075] The various operations, modules, and networks described in connection with the disclosure herein may be implemented in hardware, software executed by a processor, firmware, or any combination thereof. According an embodiment of the disclosure, a computer program product for training a quantized Bayesian Neural Network with Monte Carlo (MC) sampling may comprise processor executable computer code for performing the method 300 described above with reference to FIG. 3. According to another embodiment of the disclosure, a computer readable medium may store computer code for training a quantized Bayesian Neural Network with MC sampling. The computer code when executed by a processor may cause the processor to perform the method 300 described above with reference to FIG. 3. Computer-readable media includes both non-transitory computer storage media and communication media including any medium that facilitates transfer of a computer program from one place to another. Any connection may be properly termed as a computer-readable medium. Other embodiments and implementations are within the scope of the disclosure.
[0076] The preceding description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the various embodiments. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the scope of the various embodiments. Thus, the claims are not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the following claims and the principles and novel features disclosed herein.
Claims
1.A computer-implemented method for training a quantized Bayesian Neural Network with Monte Carlo (MC) sampling, comprising:initializing a Bayesian Neural Network (BNN) with parameters in an unquantized parameter space, wherein the BNN is used to make an inference with uncertainty based on input images;updating the parameters in the unquantized parameter space during a Metropolis-Hastings (M-H) interval;performing an M-H test to decide whether the updated parameters are acceptable, wherein an accept rate of the M-H test is calculated based on the parameters in the unquantized parameter space; andquantizing the updated parameters into a quantized parameter space with a quantizer.2.The method of claim 1, wherein the images are captured by one of camera, radar, LiDAR, ultrasonic imager, and thermal imager.3.The method of claim 1, wherein the inference made by the BNN comprises one of: whether there is anomaly in the images and whether there is a target object in the images.4.The method of claim 1, wherein the MC sampling comprises Stochastic Gradient Hamiltonian Monte Carlo (SGHMC) sampling, and wherein updating the parameters comprises updating the parameters based on a momentum of the parameters in the unquantized parameter space, the momentum being updated based on quantized parameters.5.The method of claim 1, wherein the M-H test is an approximate M-H test based on a confidence threshold, and wherein the approximate M-H test comprises:making a decision when a mini-batch of dataset is tested if the confidence threshold is set to 1; ormaking a decision after all data are drawn from dataset if the confidence threshold is set to 0.6.The method of claim 1, wherein the quantizer is an adaptive binary quantizer.7.An apparatus for training a quantized Bayesian Neural Network with Monte Carlo (MC) sampling, comprising:a memory; andat least one processor coupled to the memory and configured toinitialize a Bayesian Neural Network (BNN) with parameters in an unquantized parameter space, wherein the BNN is used to make an inference with uncertainty based on input images;update the parameters in the unquantized parameter space during a Metropolis-Hastings (M-H) interval;perform an M-H test to decide whether the updated parameters are acceptable, wherein an accept rate of the M-H test is calculated based on the parameters in the unquantized parameter space; andquantize the updated parameters into a quantized parameter space with a quantizer.8.The apparatus of claim 7, wherein the images are captured by one of camera, radar, LiDAR, ultrasonic imager, and thermal imager.9.The apparatus of claim 7, wherein the inference made by the BNN comprises one of: whether there is anomaly in the images and whether there is a target object in the images.10.The apparatus of claim 7, wherein the MC sampling comprises Stochastic Gradient Hamiltonian Monte Carlo (SGHMC) sampling, and wherein the at least one processor configured to update the parameters is configured to update the parameters based on a momentum of the parameters in the unquantized parameter space, the momentum being updated based on quantized parameters.11.The apparatus of claim 7, wherein the M-H test is an approximate M-H test based on a confidence threshold, and wherein the approximate M-H test comprises:making a decision when a mini-batch of dataset is tested if the confidence threshold is set to 1; ormaking a decision after all data are drawn from dataset if the confidence threshold is set to 0.12.The apparatus of claim 7, wherein the quantizer is an adaptive binary quantizer.13.A computer readable medium, storing computer code for training a quantized Bayesian Neural Network with Monte Carlo (MC) sampling, the computer code when executed by a processor, causing the processor to perform the method of one of claims 1-6.14.A computer program product for training a quantized Bayesian Neural Network with Monte Carlo (MC) sampling, comprising: processor executable computer code for performing the method of one of claims 1-6.