Search code, repositories, users, issues, pull requests...

This repository provides the framework for the training, testing, analysis, and comparison of uncertainty quantification in 3D segmentations via Monte Carlo dropout networks and novel Bayesian convolutional neural networks (BCNNs). BCNNs leverage the TensorFlow Probability library to learn distributions over the weights, thus performing actual Bayesian inference by learning a posterior distribution rather than approximating one like Monte Carlo dropout. Our BCNN is the first-ever Bayesian CNN with variational inference in 3D. Paper here.

  1. Install Anaconda
  2. Create a conda environment with conda create -n bcnn python==3.6.7
  3. Install package dependencies with pip install -r requirements.txt
  4. Generate the toy dataset with python generate_toy_data.py
  5. If you only have one GPU, set "num_gpus"=1 and batch_size=2 in configs/toy_config.json (it's at the bottom)
  6. Run ./toy_train_test.sh. This shell file "chunks" the large volumes and trains both a Bayesian and Monte Carlo dropout network, then compares the two on the test set. It saves model weights, prediction arrays, and sample images. In particular, check out the toy_images/*/*_unc.png images to see the differences in the uncertainty quantification output from both models. The BCNN and MCDN give approximately equivalent UQ in the toy example, but as the domains become more difficult, the BCNN achieves a clearly superior UQ performance. If you get an out-of-memory error, reduce the "batch_size" in configs/toy_config.json, delete toy_data, and start from Step 4.

3D data is a bit hard to work with, but this repo streamlines the process. We "chunk" large volumes into a manageable size by scanning them with a rectangular prism window, then reconstructing the original volume during inference time.

config.json expects data directories to be specified in the orig* variables. This is where the original large volumes are contained. The user provides whether they want to standardize the data (norm), how much overlap they want (step), and how big the window should be (window).

Data will be automatically extracted and chunked according to these config values when train.py is called.

This repo provides 4 choices of models for experimentation. There is a 2D and 3D version of both the Monte Carlo dropout network and the BCNN. Specify which model you would like to use by setting the vnet and bayesian variables in config.json. It defaults to the 3D BCNN.

One can also set model hyperparameters, including prior_std, kernel_size, activation, etc. in config.json.

To train a model, first ensure that you have the correct data_dir and weights_dir variables set in config.json. If there is a saved model in weights_dir, it will resume with the most recently edited weights file by default. If you want to disable resuming, set resume to False; if you want to resume from a specific weights file, set weights_path. By default, tf.keras does not save the epoch with the weights, so set initial_epoch if you want to resume from a specific epoch (useful because learning rate is determined by epoch). Finally, one can also set training hyperparameters such as batch_size and num_gpus. As an example,

python train.py with configs/toy_config.json "data_dir"="mydata" "num_gpus"=2 "batch_size"=32 "prior_std"=1.5

Testing a model works much the same as training, with the additional impact of Monte Carlo samples. Depending on the variance of your model, you may need different amounts of samples. I found 5-10 to work for dropout models and ~30 to work for BCNNs. test.py will save the predictions and a few image slices automatically, so ensure to specify predict_dir and images_dir. As an example,

python test.py with configs/toy_config.json "bayesian"=False "mc_samples"=12 "weights_path"="model.h5"


(*) Bản quyền bài viết thuộc về SachHay24H.com. Khi chia sẻ, cần phải dẫn link, trích dẫn nguồn đầy đủ về SachHay24h.Com. Mọi hành vi sao chép hoặc trích nguồn, chia sẻ bài viết không đầy đủ đều không được chấp nhận và phải gỡ bỏ.
Go HomePage: Sách Hay 24H hoặc click: Sách hay nhất mọi thời đại, Mua sách online, Bạn đắt giá bao nhiêu, Truyện cổ tích Việt Nam, Mùa xuân nho nhỏ, Tràng giang, Hịch tướng sĩ

Sách cùng danh mục

Top 10 Best Humans in the World

Top 10 Best Humans in the World

Con đường đến trường lớp 3 - Kết nối tri thức

Con đường đến trường lớp 3 - Kết nối tri thức

Giáo án điện tử ngữ văn 9 tiết: Tổng kết phần văn học nước ngoài

Giáo án điện tử ngữ văn 9 tiết: Tổng kết phần văn học nước ngoài

Giới Thiệu Bài Thơ Từ Ấy - Tố Hữu (Trọn bài thơ)

Giới Thiệu Bài Thơ Từ Ấy - Tố Hữu (Trọn bài thơ)

Lý thuyết hệ thức lượng trong tam giác vuông: Công thức, bài tập lớp 9

Lý thuyết hệ thức lượng trong tam giác vuông: Công thức, bài tập lớp 9

10+ Viết bài văn tả cảnh trường em vào giờ ra chơi (điểm cao)

10+ Viết bài văn tả cảnh trường em vào giờ ra chơi (điểm cao)

Sách đọc nhiều nhất
Công thức tọa độ trung điểm (siêu hay)

Công thức tọa độ trung điểm (siêu hay)

Công thức tọa độ trung điểm (siêu hay)

Giáo dục

Giáo dục

Giáo dục

Soạn bài Dương phụ hành Kết nối tri thức                               Ngữ văn lớp 11 trang 107 sách Kết nối tri thức tập 1

Soạn bài Dương phụ hành Kết nối tri thức Ngữ văn lớp 11 trang 107 sách Kết nối tri thức tập 1

Soạn bài Dương phụ hành Kết nối tri thức Ngữ văn lớp 11 trang 107 sách Kết...

Đóng vai người lính kể lại bài thơ Đồng chí của Chính Hữu điểm cao

Đóng vai người lính kể lại bài thơ Đồng chí của Chính Hữu điểm cao

Đóng vai người lính kể lại bài thơ Đồng chí của Chính Hữu điểm cao

Thơ Đường luật là gì (chi tiết nhất)

Thơ Đường luật là gì (chi tiết nhất)

Thơ Đường luật là gì (chi tiết nhất)

Xéo xắt hay Xéo sắc? Từ nào mới đúng để chỉ sự chua ngoa?

Xéo xắt hay Xéo sắc? Từ nào mới đúng để chỉ sự chua ngoa?

Xéo xắt hay Xéo sắc? Từ nào mới đúng để chỉ sự chua ngoa?

Review sách hay, sách hay nên đọc tại Sách Hay 24H.