Skip to content

Commit

Permalink
update 2.0 public api in vision
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiboniu committed Jun 9, 2021
1 parent 5d8e439 commit cd489d0
Show file tree
Hide file tree
Showing 25 changed files with 200 additions and 92 deletions.
8 changes: 4 additions & 4 deletions python/paddle/hapi/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class ProgBarLogger(Callback):
])
train_dataset = MNIST(mode='train', transform=transform)
lenet = paddle.vision.LeNet()
lenet = paddle.vision.models.LeNet()
model = paddle.Model(lenet,
inputs, labels)
Expand Down Expand Up @@ -554,7 +554,7 @@ class ModelCheckpoint(Callback):
])
train_dataset = MNIST(mode='train', transform=transform)
lenet = paddle.vision.LeNet()
lenet = paddle.vision.models.LeNet()
model = paddle.Model(lenet,
inputs, labels)
Expand Down Expand Up @@ -614,7 +614,7 @@ class LRScheduler(Callback):
])
train_dataset = paddle.vision.datasets.MNIST(mode='train', transform=transform)
lenet = paddle.vision.LeNet()
lenet = paddle.vision.models.LeNet()
model = paddle.Model(lenet,
inputs, labels)
Expand Down Expand Up @@ -856,7 +856,7 @@ class VisualDL(Callback):
train_dataset = paddle.vision.datasets.MNIST(mode='train', transform=transform)
eval_dataset = paddle.vision.datasets.MNIST(mode='test', transform=transform)
net = paddle.vision.LeNet()
net = paddle.vision.models.LeNet()
model = paddle.Model(net, inputs, labels)
optim = paddle.optimizer.Adam(0.001, parameters=net.parameters())
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/hapi/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2080,7 +2080,7 @@ def summary(self, input_size=None, dtype=None):
input = InputSpec([None, 1, 28, 28], 'float32', 'image')
label = InputSpec([None, 1], 'int64', 'label')
model = paddle.Model(paddle.vision.LeNet(),
model = paddle.Model(paddle.vision.models.LeNet(),
input, label)
optim = paddle.optimizer.Adam(
learning_rate=0.001, parameters=model.parameters())
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/metric/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class Accuracy(Metric):
transform = T.Compose([T.Transpose(), T.Normalize([127.5], [127.5])])
train_dataset = MNIST(mode='train', transform=transform)
model = paddle.Model(paddle.vision.LeNet(), input, label)
model = paddle.Model(paddle.vision.models.LeNet(), input, label)
optim = paddle.optimizer.Adam(
learning_rate=0.001, parameters=model.parameters())
model.prepare(
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/tests/test_callback_visualdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_visualdl_callback(self):
train_dataset = MnistDataset(mode='train', transform=transform)
eval_dataset = MnistDataset(mode='test', transform=transform)

net = paddle.vision.LeNet()
net = paddle.vision.models.LeNet()
model = paddle.Model(net, inputs, labels)

optim = paddle.optimizer.Adam(0.001, parameters=net.parameters())
Expand Down
63 changes: 50 additions & 13 deletions python/paddle/vision/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,59 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import paddle
import paddle.nn as nn
from . import models # noqa: F401
from . import transforms # noqa: F401
from . import datasets # noqa: F401
from . import ops # noqa: F401
from .image import set_image_backend # noqa: F401
from .image import get_image_backend # noqa: F401
from .image import image_load # noqa: F401
from .models import LeNet as models_LeNet
import paddle.utils.deprecated as deprecated

from . import models
from .models import *
__all__ = [ #noqa
'set_image_backend', 'get_image_backend', 'image_load'
]

from . import transforms
from .transforms import *

from . import datasets
from .datasets import *
class LeNet(models_LeNet):
"""LeNet model from
`"LeCun Y, Bottou L, Bengio Y, et al. Gradient-based learning applied to document recognition[J]. Proceedings of the IEEE, 1998, 86(11): 2278-2324.`_
from . import image
from .image import *
Args:
num_classes (int): output dim of last fc layer. If num_classes <=0, last fc layer
will not be defined. Default: 10.
from . import ops
Examples:
.. code-block:: python
__all__ = models.__all__ \
+ transforms.__all__ \
+ datasets.__all__ \
+ image.__all__
from paddle.vision.models import LeNet
model = LeNet()
"""

@deprecated(
since="2.0.0",
update_to="paddle.vision.models.LeNet",
level=1,
reason="Please use new API in models, paddle.vision.LeNet will be removed in future"
)
def __init__(self, num_classes=10):
super(LeNet, self).__init__(num_classes=10)
self.num_classes = num_classes
self.features = nn.Sequential(
nn.Conv2D(
1, 6, 3, stride=1, padding=1),
nn.ReLU(),
nn.MaxPool2D(2, 2),
nn.Conv2D(
6, 16, 5, stride=1, padding=0),
nn.ReLU(),
nn.MaxPool2D(2, 2))

if num_classes > 0:
self.fc = nn.Sequential(
nn.Linear(400, 120),
nn.Linear(120, 84), nn.Linear(84, num_classes))
34 changes: 18 additions & 16 deletions python/paddle/vision/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from . import folder
from . import mnist
from . import flowers
from . import cifar
from . import voc2012
from .folder import DatasetFolder # noqa: F401
from .folder import ImageFolder # noqa: F401
from .mnist import MNIST # noqa: F401
from .mnist import FashionMNIST # noqa: F401
from .flowers import Flowers # noqa: F401
from .cifar import Cifar10 # noqa: F401
from .cifar import Cifar100 # noqa: F401
from .voc2012 import VOC2012 # noqa: F401

from .folder import *
from .mnist import *
from .flowers import *
from .cifar import *
from .voc2012 import *

__all__ = folder.__all__ \
+ mnist.__all__ \
+ flowers.__all__ \
+ cifar.__all__ \
+ voc2012.__all__
__all__ = [ #noqa
'DatasetFolder'
'ImageFolder',
'MNIST',
'FashionMNIST',
'Flowers',
'Cifar10',
'Cifar100',
'VOC2012'
]
2 changes: 1 addition & 1 deletion python/paddle/vision/datasets/cifar.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from paddle.io import Dataset
from paddle.dataset.common import _check_exists_and_download

__all__ = ['Cifar10', 'Cifar100']
__all__ = []

URL_PREFIX = 'https://dataset.bj.bcebos.com/cifar/'
CIFAR10_URL = URL_PREFIX + 'cifar-10-python.tar.gz'
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/vision/datasets/flowers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from paddle.utils import try_import
from paddle.dataset.common import _check_exists_and_download

__all__ = ["Flowers"]
__all__ = []

DATA_URL = 'http://paddlemodels.bj.bcebos.com/flowers/102flowers.tgz'
LABEL_URL = 'http://paddlemodels.bj.bcebos.com/flowers/imagelabels.mat'
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/vision/datasets/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from paddle.io import Dataset
from paddle.utils import try_import

__all__ = ["DatasetFolder", "ImageFolder"]
__all__ = []


def has_valid_extension(filename, extensions):
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/vision/datasets/mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from paddle.io import Dataset
from paddle.dataset.common import _check_exists_and_download

__all__ = ["MNIST", "FashionMNIST"]
__all__ = []


class MNIST(Dataset):
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/vision/datasets/voc2012.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from paddle.io import Dataset
from paddle.dataset.common import _check_exists_and_download

__all__ = ["VOC2012"]
__all__ = []

VOC_URL = 'https://dataset.bj.bcebos.com/voc/VOCtrainval_11-May-2012.tar'

Expand Down
2 changes: 1 addition & 1 deletion python/paddle/vision/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from PIL import Image
from paddle.utils import try_import

__all__ = ['set_image_backend', 'get_image_backend', 'image_load']
__all__ = []

_image_backend = 'pil'

Expand Down
50 changes: 34 additions & 16 deletions python/paddle/vision/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,38 @@
#See the License for the specific language governing permissions and
#limitations under the License.

from . import resnet
from . import vgg
from . import mobilenetv1
from . import mobilenetv2
from . import lenet
from .resnet import ResNet # noqa: F401
from .resnet import resnet18 # noqa: F401
from .resnet import resnet34 # noqa: F401
from .resnet import resnet50 # noqa: F401
from .resnet import resnet101 # noqa: F401
from .resnet import resnet152 # noqa: F401
from .mobilenetv1 import MobileNetV1 # noqa: F401
from .mobilenetv1 import mobilenet_v1 # noqa: F401
from .mobilenetv2 import MobileNetV2 # noqa: F401
from .mobilenetv2 import mobilenet_v2 # noqa: F401
from .vgg import VGG # noqa: F401
from .vgg import vgg11 # noqa: F401
from .vgg import vgg13 # noqa: F401
from .vgg import vgg16 # noqa: F401
from .vgg import vgg19 # noqa: F401
from .lenet import LeNet # noqa: F401

from .resnet import *
from .mobilenetv1 import *
from .mobilenetv2 import *
from .vgg import *
from .lenet import *

__all__ = resnet.__all__ \
+ vgg.__all__ \
+ mobilenetv1.__all__ \
+ mobilenetv2.__all__ \
+ lenet.__all__
__all__ = [ #noqa
'ResNet',
'resnet18',
'resnet34',
'resnet50',
'resnet101',
'resnet152',
'VGG',
'vgg11',
'vgg13',
'vgg16',
'vgg19',
'MobileNetV1',
'mobilenet_v1',
'MobileNetV2',
'mobilenet_v2',
'LeNet'
]
2 changes: 1 addition & 1 deletion python/paddle/vision/models/lenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import paddle
import paddle.nn as nn

__all__ = ['LeNet']
__all__ = []


class LeNet(nn.Layer):
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/vision/models/mobilenetv1.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from paddle.utils.download import get_weights_path_from_url

__all__ = ['MobileNetV1', 'mobilenet_v1']
__all__ = []

model_urls = {
'mobilenetv1_1.0':
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/vision/models/mobilenetv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from paddle.utils.download import get_weights_path_from_url

__all__ = ['MobileNetV2', 'mobilenet_v2']
__all__ = []

model_urls = {
'mobilenetv2_1.0':
Expand Down
4 changes: 1 addition & 3 deletions python/paddle/vision/models/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

from paddle.utils.download import get_weights_path_from_url

__all__ = [
'ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101', 'resnet152'
]
__all__ = []

model_urls = {
'resnet18': ('https://paddle-hapi.bj.bcebos.com/models/resnet18.pdparams',
Expand Down
8 changes: 1 addition & 7 deletions python/paddle/vision/models/vgg.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@

from paddle.utils.download import get_weights_path_from_url

__all__ = [
'VGG',
'vgg11',
'vgg13',
'vgg16',
'vgg19',
]
__all__ = []

model_urls = {
'vgg16': ('https://paddle-hapi.bj.bcebos.com/models/vgg16.pdparams',
Expand Down
8 changes: 6 additions & 2 deletions python/paddle/vision/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@

from paddle.common_ops_import import *

__all__ = [
'yolo_loss', 'yolo_box', 'deform_conv2d', 'DeformConv2D', 'read_file',
__all__ = [ #noqa
'yolo_loss',
'yolo_box',
'deform_conv2d',
'DeformConv2D',
'read_file',
'decode_jpeg'
]

Expand Down
Loading

1 comment on commit cd489d0

@paddle-bot-old
Copy link

@paddle-bot-old paddle-bot-old bot commented on cd489d0 Jun 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵️ CI failures summary

🔍PR: #33307 Commit ID: cd489d0 contains failed CI.

Please sign in to comment.