Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/seg/deeplabv3/deeplabv3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""DeeplabV3, DeeplabV3+ implement with replaceable backbones"""
"""
DeeplabV3, DeeplabV3+ implement with replaceable backbones
Adapted from https://github.com/pytorch/vision/blob/main/torchvision/models/segmentation/deeplabv3.py
"""

from typing import List

Expand Down
2 changes: 2 additions & 0 deletions examples/seg/deeplabv3/preprocess/build_seg_data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copy from https://github.com/mindspore-ai/models/blob/master/official/cv/DeepLabv3/src/data/build_seg_data.py

import argparse
import os

Expand Down
2 changes: 2 additions & 0 deletions examples/seg/deeplabv3/preprocess/get_data_list.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copy from https://github.com/mindspore-ai/models/blob/master/official/cv/DeepLabv3/src/data/get_dataset_lst.py

import argparse
import os

Expand Down
10 changes: 8 additions & 2 deletions mindcv/data/auto_augment.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
"""
AutoAugment and RandAugment for mindspore.

Copyright 2019, Ross Wightman

Modifications made by MindSpore team in 2023 to support the MindSpore framework.
Adapted from:
https://github.com/rwightman/pytorch-image-models/blob/main/timm/data/auto_augment.py
https://github.com/rwightman/pytorch-image-models/blob/main/timm/data/auto_augment.py.



AutoAugment and RandAugment for mindspore.

Papers:
AutoAugment: Learning Augmentation Policies from Data - https://arxiv.org/abs/1805.09501
Expand Down
2 changes: 1 addition & 1 deletion mindcv/data/dataset_factory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Create dataset by name
Create dataset by name on MindSpore
"""

import logging
Expand Down
3 changes: 2 additions & 1 deletion mindcv/data/distributed_sampler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" distributed sampler """
""" MindSpore Distributed Sampler """

import logging
import math

Expand Down
2 changes: 1 addition & 1 deletion mindcv/data/loader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Create dataloader
Create dataloader on MindSpore
"""

import inspect
Expand Down
4 changes: 4 additions & 0 deletions mindcv/data/mixup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
CutMix: https://github.com/clovaai/CutMix-PyTorch

Hacked together by / Copyright 2020 Ross Wightman

Modifications made to support the MindSpore framework.
Adapted from https://github.com/huggingface/pytorch-image-models/blob/main/timm/data/mixup.py

"""
import numpy as np

Expand Down
5 changes: 5 additions & 0 deletions mindcv/data/transforms_factory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""
Transform operation list

Hacked together by / Copyright 2019, Ross Wightman
Modifications made to support the MindSpore framework.
Adapted from https://github.com/huggingface/pytorch-image-models/blob/main/timm/data/transforms_factory.py

"""

import math
Expand Down
1 change: 1 addition & 0 deletions mindcv/models/bit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
MindSpore implementation of `BiT_ResNet`.
Refer to Big Transfer (BiT): General Visual Representation Learning.
Adapted from https://github.com/google-research/big_transfer.
"""

from typing import List, Optional, Type, Union
Expand Down
20 changes: 17 additions & 3 deletions mindcv/models/cait.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
""" Class-Attention in Image Transformers (CaiT)

Paper: 'Going deeper with Image Transformers' - https://arxiv.org/abs/2103.17239

Original code and weights from https://github.com/facebookresearch/deit, copyright below

Modifications and additions for timm hacked together by / Copyright 2021, Ross Wightman

------------------------------------------------------------------------
MindSpore adaptation:
Modified for use with the MindSpore framework.
This file is part of a derivative work and remains under the original license.
Adapted from https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/cait.py
"""
MindSpore implementation of `CaiT`.
Refer to Going deeper with Image Transformers.
"""

# Copyright (c) 2015-present, Facebook, Inc.
# All rights reserved.


from functools import partial

Expand Down
4 changes: 4 additions & 0 deletions mindcv/models/cmt.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
MindSpore implementation of `CMT`.
Adapted from https://github.com/junjie18/CMT
"""
import numpy as np

import mindspore
Expand Down
10 changes: 10 additions & 0 deletions mindcv/models/coat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
"""
CoaT architecture.
Paper: Co-Scale Conv-Attentional Image Transformers - https://arxiv.org/abs/2104.06399

Official CoaT code at: https://github.com/mlpc-ucsd/CoaT
Modified from timm/models/vision_transformer.py

------------------------------------------------------------------------
MindSpore adaptation:
Modified for use with the MindSpore framework.
This file is part of a derivative work and remains under the original license.
Adapted from https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/coat.py

"""
from typing import Union

Expand Down
31 changes: 28 additions & 3 deletions mindcv/models/convit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
""" ConViT Model

@article{d2021convit,
title={ConViT: Improving Vision Transformers with Soft Convolutional Inductive Biases},
author={d'Ascoli, St{\'e}phane and Touvron, Hugo and Leavitt, Matthew and Morcos,
Ari and Biroli, Giulio and Sagun, Levent},
journal={arXiv preprint arXiv:2103.10697},
year={2021}
}

Paper link: https://arxiv.org/abs/2103.10697
Original code: https://github.com/facebookresearch/convit, original copyright below

Modifications and additions for timm hacked together by / Copyright 2021, Ross Wightman

------------------------------------------------------------------------
MindSpore adaptation:
Modified for use with the MindSpore framework.
This file is part of a derivative work and remains under the original license.
Adapted from https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/convit.py

"""
MindSpore implementation of `ConViT`.
Refer to ConViT: Improving Vision Transformers with Soft Convolutional Inductive Biases
"""

# Copyright (c) 2015-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the CC-by-NC license found in the
# LICENSE file in the root directory of this source tree.
#

import numpy as np

Expand Down
50 changes: 46 additions & 4 deletions mindcv/models/convnext.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,50 @@
""" ConvNeXt

Papers:
* `A ConvNet for the 2020s` - https://arxiv.org/pdf/2201.03545.pdf
@Article{liu2022convnet,
author = {Zhuang Liu and Hanzi Mao and Chao-Yuan Wu and Christoph Feichtenhofer and Trevor Darrell and Saining Xie},
title = {A ConvNet for the 2020s},
journal = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
year = {2022},
}

* `ConvNeXt-V2 - Co-designing and Scaling ConvNets with Masked Autoencoders` - https://arxiv.org/abs/2301.00808
@article{Woo2023ConvNeXtV2,
title={ConvNeXt V2: Co-designing and Scaling ConvNets with Masked Autoencoders},
author={Sanghyun Woo, Shoubhik Debnath, Ronghang Hu, Xinlei Chen, Zhuang Liu, In So Kweon and Saining Xie},
year={2023},
journal={arXiv preprint arXiv:2301.00808},
}

Original code and weights from:
* https://github.com/facebookresearch/ConvNeXt, original copyright below
* https://github.com/facebookresearch/ConvNeXt-V2, original copyright below

Model defs atto, femto, pico, nano and _ols / _hnf variants are timm originals.

Modifications and additions for timm hacked together by / Copyright 2022, Ross Wightman

------------------------------------------------------------------------
MindSpore adaptation:
Modified for use with the MindSpore framework.
This file is part of a derivative work and remains under the original license.
Adapted from https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/convnext.py

"""
MindSpore implementation of `ConvNeXt` and `ConvNeXt V2`.
Refer to: A ConvNet for the 2020s
ConvNeXt V2: Co-designing and Scaling ConvNets with Masked Autoencoders
"""
# ConvNeXt
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the MIT license

# ConvNeXt-V2
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree (Attribution-NonCommercial 4.0 International (CC BY-NC 4.0))
# No code was used directly from ConvNeXt-V2, however the weights are CC BY-NC 4.0 so beware if using commercially.


from typing import List, Tuple

import numpy as np
Expand Down
30 changes: 27 additions & 3 deletions mindcv/models/crossvit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
""" CrossViT Model

@inproceedings{
chen2021crossvit,
title={{CrossViT: Cross-Attention Multi-Scale Vision Transformer for Image Classification}},
author={Chun-Fu (Richard) Chen and Quanfu Fan and Rameswar Panda},
booktitle={International Conference on Computer Vision (ICCV)},
year={2021}
}

Paper link: https://arxiv.org/abs/2103.14899
Original code: https://github.com/IBM/CrossViT/blob/main/models/crossvit.py

NOTE: model names have been renamed from originals to represent actual input res all *_224 -> *_240 and *_384 -> *_408

Modifications and additions for timm hacked together by / Copyright 2021, Ross Wightman
Modified from Timm. https://github.com/rwightman/pytorch-image-models/blob/master/timm/models/vision_transformer.py

------------------------------------------------------------------------
MindSpore adaptation:
Modified for use with the MindSpore framework.
This file is part of a derivative work and remains under the original license.
Adapted from https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/crossvit.py

"""
MindSpore implementation of `crossvit`.
Refer to crossvit: Cross-Attention Multi-Scale Vision Transformer for Image Classification
"""

# Copyright IBM All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion mindcv/models/densenet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
MindSpore implementation of `DenseNet`.
Refer to: Densely Connected Convolutional Networks
Adapted from https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/densenet.py
"""

import math
Expand Down
14 changes: 12 additions & 2 deletions mindcv/models/dpn.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
"""
MindSpore implementation of `DPN`.
Refer to: Dual Path Networks
Based on original MXNet implementation https://github.com/cypw/DPNs with
many ideas from another PyTorch implementation https://github.com/oyam/pytorch-DPNs.

This implementation is compatible with the pretrained weights from cypw's MXNet implementation.

Hacked together by / Copyright 2020 Ross Wightman

------------------------------------------------------------------------
MindSpore adaptation:
Modified for use with the MindSpore framework.
This file is part of a derivative work and remains under the original license.
Adapted from https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/dpn.py
"""

import math
Expand Down
15 changes: 13 additions & 2 deletions mindcv/models/edgenext.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
"""
MindSpore implementation of `edgenext`.
Refer to EdgeNeXt: Efficiently Amalgamated CNN-Transformer Architecture for Mobile Vision Applications.
Paper: `EdgeNeXt: Efficiently Amalgamated CNN-Transformer Architecture for Mobile Vision Applications`
- https://arxiv.org/abs/2206.10589

Original code and weights from https://github.com/mmaaz60/EdgeNeXt

Modifications and additions for timm by / Copyright 2022, Ross Wightman

------------------------------------------------------------------------
MindSpore adaptation:
Modified for use with the MindSpore framework.
This file is part of a derivative work and remains under the original license.
Adapted from https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/edgenext.py

"""

import math
Expand Down
11 changes: 10 additions & 1 deletion mindcv/models/efficientnet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
"""EfficientNet Architecture."""
"""EfficientNet Architecture.
Hacked together by / Copyright 2019, Ross Wightman

------------------------------------------------------------------------
MindSpore adaptation:
Modified for use with the MindSpore framework.
This file is part of a derivative work and remains under the original license.
Adapted from https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/efficientnet.py

"""

import copy
import math
Expand Down
2 changes: 1 addition & 1 deletion mindcv/models/ghostnet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""MindSpore implementation of `GhostNet`.
Refer to GhostNet: More Features from Cheap Operations.
Adapted from https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/ghostnet.py
"""

import math
Expand Down
1 change: 1 addition & 0 deletions mindcv/models/halonet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
MindSpore implementation of `HaloNet`.
Refer to Scaling Local Self-Attention for Parameter Effificient Visual Backbones.
Adapted from https://github.com/maurbe/halo-net
"""
import mindspore as ms
import mindspore.common.initializer as init
Expand Down
11 changes: 10 additions & 1 deletion mindcv/models/hrnet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
"""
Copied from https://github.com/HRNet/HRNet-Image-Classification

Original header:
Copyright (c) Microsoft
Licensed under the MIT License.
Written by Bin Xiao (Bin.Xiao@microsoft.com)
Modified by Ke Sun (sunk@mail.ustc.edu.cn)

------------------------------------------------------------------------
MindSpore implementation of `HRNet`.
Refer to Deep High-Resolution Representation Learning for Visual Recognition
Adapted from https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/hrnet.py
"""
from typing import Any, Dict, List, Optional, Tuple, Type, Union

Expand Down
4 changes: 4 additions & 0 deletions mindcv/models/inceptionv3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""
Originally from torchvision Inception3 model
Licensed BSD-Clause 3 https://github.com/pytorch/vision/blob/master/LICENSE

MindSpore implementation of `InceptionV3`.
Refer to Rethinking the Inception Architecture for Computer Vision.
Adapted from https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/inception_v3.py
"""

from typing import Tuple, Union
Expand Down
5 changes: 5 additions & 0 deletions mindcv/models/inceptionv4.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"""
Sourced from https://github.com/Cadene/tensorflow-model-zoo.torch (MIT License) which is
based upon Google's Tensorflow implementation and pretrained weights (Apache 2.0 License)


MindSpore implementation of `InceptionV4`.
Refer to Inception-v4, Inception-ResNet and the Impact of Residual Connections on Learning.
Adapted from https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/inception_v4.py
"""

from typing import Tuple, Union
Expand Down
2 changes: 2 additions & 0 deletions mindcv/models/layers/compatibility.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Adapted from https://github.com/huggingface/pytorch-image-models/tree/main/timm/layers

import inspect

import mindspore as ms
Expand Down
4 changes: 3 additions & 1 deletion mindcv/models/layers/conv_norm_act.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
""" Conv2d + BN + Act"""
""" Conv2d + BN + Act
Adapted from https://github.com/huggingface/pytorch-image-models/tree/main/timm/layers
"""
from typing import Optional

from mindspore import nn
Expand Down
Loading
Loading