# EfficientNet-PyTorch-3D **Repository Path**: khanx/EfficientNet-PyTorch-3D ## Basic Information - **Project Name**: EfficientNet-PyTorch-3D - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-08-21 - **Last Updated**: 2025-08-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # EfficientNet PyTorch 3D Version is based on top of [EfficientNet-Pytorch](https://github.com/lukemelas/EfficientNet-PyTorch). For similar usage, you may install like: ```bash pip install git+https://github.com/shijianjian/EfficientNet-PyTorch-3D ``` ```python from efficientnet_pytorch_3d import EfficientNet3D import torch model = EfficientNet3D.from_name("efficientnet-b0", override_params={'num_classes': 2}, in_channels=1) from torchsummary import summary summary(model, input_size=(1, 200, 200, 200)) model = model.cuda() inputs = torch.randn((1, 1, 200, 200, 200)).cuda() labels = torch.tensor([0]).cuda() # test forward num_classes = 2 criterion = torch.nn.CrossEntropyLoss() optimizer = torch.optim.SGD(model.parameters(), lr=0.001, momentum=0.9) model.train() for epoch in range(2): # zero the parameter gradients optimizer.zero_grad() # forward + backward + optimize outputs = model(inputs) loss = criterion(outputs, labels) loss.backward() optimizer.step() # print statistics print('[%d] loss: %.3f' % (epoch + 1, loss.item())) print('Finished Training') ``` 3D EfficientNet has a high GPU cost. Here, the ```block_args``` for the first block is altered from ```'r1_k3_s111_e1_i32_o16_se0.25'``` to ```'r1_k3_s222_e1_i32_o16_se0.25'``` to save GPU memories. Take an example from EfficientNet-b0 with an input size of (1, 200, 200, 200): - Stide 1 for the first block will cost 8703.64 MB GPU Memories. - Strde 2 for the first block will cost 2023.29 MB GPU Memories. Take an example from EfficientNet-b0 with an input size of (1, 200, 1024, 200): - Stide 1 for the first block will cost 44387.63 MB GPU Memories, which will not be loaded into any single GPUs currently. - Strde 2 for the first block will cost 10283.67 MB GPU Memories, which is relatively acceptable. Mostly, we can save 4 times GPU memories by reducing the stride from the first block from 1 to 2. Below is the README from the original repo: _IMPORTANT NOTE_: In the latest update, I switched hosting providers for the pretrained models, as the previous models were becoming extremely expensive to host. This _will_ break old versions of the library. I apologize, but I cannot afford to keep serving the models on the old provider. Everything should work properly if you update the library: ``` pip install --upgrade efficientnet-pytorch ``` ### Update (January 23, 2020) This update adds a new category of pre-trained model based on adversarial training, called _advprop_. It is important to note that the preprocessing required for the advprop pretrained models is slightly different from normal ImageNet preprocessing. As a result, by default, advprop models are not used. To load a model with advprop, use: ``` model = EfficientNet.from_pretrained("efficientnet-b0", advprop=True) ``` There is also a new, large `efficientnet-b8` pretrained model that is only available in advprop form. When using these models, replace ImageNet preprocessing code as follows: ``` if advprop: # for models using advprop pretrained weights normalize = transforms.Lambda(lambda img: img * 2.0 - 1.0) else: normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) ``` This update also addresses multiple other issues ([#115](https://github.com/lukemelas/EfficientNet-PyTorch/issues/115), [#128](https://github.com/lukemelas/EfficientNet-PyTorch/issues/128)). ### Update (October 15, 2019) This update allows you to choose whether to use a memory-efficient Swish activation. The memory-efficient version is chosen by default, but it cannot be used when exporting using PyTorch JIT. For this purpose, we have also included a standard (export-friendly) swish activation function. To switch to the export-friendly version, simply call `model.set_swish(memory_efficient=False)` after loading your desired model. This update addresses issues [#88](https://github.com/lukemelas/EfficientNet-PyTorch/pull/88) and [#89](https://github.com/lukemelas/EfficientNet-PyTorch/pull/89). ### Update (October 12, 2019) This update makes the Swish activation function more memory-efficient. It also addresses pull requests [#72](https://github.com/lukemelas/EfficientNet-PyTorch/pull/72), [#73](https://github.com/lukemelas/EfficientNet-PyTorch/pull/73), [#85](https://github.com/lukemelas/EfficientNet-PyTorch/pull/85), and [#86](https://github.com/lukemelas/EfficientNet-PyTorch/pull/86). Thanks to the authors of all the pull requests! ### Update (July 31, 2019) _Upgrade the pip package with_ `pip install --upgrade efficientnet-pytorch` The B6 and B7 models are now available. Additionally, _all_ pretrained models have been updated to use AutoAugment preprocessing, which translates to better performance across the board. Usage is the same as before: ```python from efficientnet_pytorch import EfficientNet model = EfficientNet.from_pretrained('efficientnet-b7') ``` ### Update (June 29, 2019) This update adds easy model exporting ([#20](https://github.com/lukemelas/EfficientNet-PyTorch/issues/20)) and feature extraction ([#38](https://github.com/lukemelas/EfficientNet-PyTorch/issues/38)). * [Example: Export to ONNX](#example-export) * [Example: Extract features](#example-feature-extraction) * Also: fixed a CUDA/CPU bug ([#32](https://github.com/lukemelas/EfficientNet-PyTorch/issues/32)) It is also now incredibly simple to load a pretrained model with a new number of classes for transfer learning: ```python model = EfficientNet.from_pretrained('efficientnet-b1', num_classes=23) ``` ### Update (June 23, 2019) The B4 and B5 models are now available. Their usage is identical to the other models: ```python from efficientnet_pytorch import EfficientNet model = EfficientNet.from_pretrained('efficientnet-b4') ``` ### Overview This repository contains an op-for-op PyTorch reimplementation of [EfficientNet](https://arxiv.org/abs/1905.11946), along with pre-trained models and examples. The goal of this implementation is to be simple, highly extensible, and easy to integrate into your own projects. This implementation is a work in progress -- new features are currently being implemented. At the moment, you can easily: * Load pretrained EfficientNet models * Use EfficientNet models for classification or feature extraction * Evaluate EfficientNet models on ImageNet or your own images _Upcoming features_: In the next few days, you will be able to: * Train new models from scratch on ImageNet with a simple command * Quickly finetune an EfficientNet on your own dataset * Export EfficientNet models for production ### Table of contents 1. [About EfficientNet](#about-efficientnet) 2. [About EfficientNet-PyTorch](#about-efficientnet-pytorch) 3. [Installation](#installation) 4. [Usage](#usage) * [Load pretrained models](#loading-pretrained-models) * [Example: Classify](#example-classification) * [Example: Extract features](#example-feature-extraction) * [Example: Export to ONNX](#example-export) 6. [Contributing](#contributing) ### About EfficientNet If you're new to EfficientNets, here is an explanation straight from the official TensorFlow implementation: EfficientNets are a family of image classification models, which achieve state-of-the-art accuracy, yet being an order-of-magnitude smaller and faster than previous models. We develop EfficientNets based on AutoML and Compound Scaling. In particular, we first use [AutoML Mobile framework](https://ai.googleblog.com/2018/08/mnasnet-towards-automating-design-of.html) to develop a mobile-size baseline network, named as EfficientNet-B0; Then, we use the compound scaling method to scale up this baseline to obtain EfficientNet-B1 to B7.
|
|