python 关键字之super
来源:互联网 发布:php去掉所有html标签 编辑:程序博客网 时间:2024/06/07 13:43
class C(B): def method(self, arg): super(C, self).method(arg)
子类C重写了父类B中同名方法method,在重写的实现中通过super实例化的代理对象调用父类的同名方法。
举例如下
class BaseSuperResolutionModel(object): def __init__(self, model_name, scale_factor): """ Base model to provide a standard interface of adding Super Resolution models """ self.model = None # type: Model self.model_name = model_name self.scale_factor = scale_factor self.weight_path = None self.type_scale_type = "norm" # Default = "norm" = 1. / 255 self.type_requires_divisible_shape = False self.type_true_upscaling = False self.evaluation_func = None self.uses_learning_phase = False def create_model(self, height=32, width=32, channels=3, load_weights=False, batch_size=128) -> Model: """ Subclass dependent implementation. """ if self.type_requires_divisible_shape: assert height * img_utils._image_scale_multiplier % 4 == 0, "Height of the image must be divisible by 4" assert width * img_utils._image_scale_multiplier % 4 == 0, "Width of the image must be divisible by 4" if K.image_dim_ordering() == "th": shape = (channels, width * img_utils._image_scale_multiplier, height * img_utils._image_scale_multiplier) else: shape = (width * img_utils._image_scale_multiplier, height * img_utils._image_scale_multiplier, channels) init = Input(shape=shape) return initclass ImageSuperResolutionModel(BaseSuperResolutionModel): def __init__(self, scale_factor): super(ImageSuperResolutionModel, self).__init__("Image SR", scale_factor) self.f1 = 9 self.f2 = 1 self.f3 = 5 self.n1 = 64 self.n2 = 32 self.weight_path = "weights/SR Weights %dX.h5" % (self.scale_factor) def create_model(self, height=32, width=32, channels=3, load_weights=False, batch_size=128): """ Creates a model to be used to scale images of specific height and width. """ init = super(ImageSuperResolutionModel, self).create_model(height, width, channels, load_weights, batch_size) x = Convolution2D(self.n1, self.f1, self.f1, activation='relu', border_mode='same', name='level1')(init) x = Convolution2D(self.n2, self.f2, self.f2, activation='relu', border_mode='same', name='level2')(x) out = Convolution2D(channels, self.f3, self.f3, border_mode='same', name='output')(x) model = Model(init, out) adam = optimizers.Adam(lr=1e-3) model.compile(optimizer=adam, loss='mse', metrics=[PSNRLoss]) if load_weights: model.load_weights(self.weight_path) self.model = modelreturn model
super(ImageSuperResolutionModel, self).__init__("Image SR", scale_factor) 继承了基类中的初始化方法
0 0
- python 关键字之super
- Python之路--super关键字
- python super关键字
- Python super关键字
- android 之 super关键字
- Java之关键字super
- Java之super关键字
- java关键字之super
- Java之super关键字
- Python3之super关键字
- Python3之super关键字
- 关键字之this和super
- java基础之super关键字
- java关键字之—super
- Python之super函数
- 【Python】关键字import与super介绍
- Python中super关键字的作用
- Python中super关键字的作用
- 斜率优化dp 学习笔记
- 使用Python创建简单的HTTP和FTP服务
- 码农之记录那些我踩过的坑
- a+b Problem
- java 设计模式-单例模式
- python 关键字之super
- 《Java网络编程》摘要
- [Android新手学习笔记31]-Broadcast-本地广播
- 跟着《Python网络数据采集》学爬虫2
- 编写Makefile规则
- [Android新手学习笔记32]-Broadcast-强制下线
- 假期里入门JS的一些感受(一个小坑)
- ListView嵌套GridView出现的问题及解决方法
- 【BZOJ 1800】【AHOI 2009】飞行棋