国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python 關鍵字之super

2019-11-08 02:38:18
字體:
來源:轉載
供稿:網友
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) 繼承了基類中的初始化方法


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东海县| 镇巴县| 萝北县| 惠州市| 襄汾县| 得荣县| 纳雍县| 皋兰县| 抚远县| 婺源县| 雷波县| 林周县| 克拉玛依市| 施甸县| 屏边| 车险| 从江县| 新野县| 临汾市| 凭祥市| 山丹县| 分宜县| 囊谦县| 中牟县| 台湾省| 东乌珠穆沁旗| 长治县| 肇源县| 涟源市| 华亭县| 牟定县| 耿马| 肇庆市| 扬州市| 怀宁县| 万全县| 武义县| 三亚市| 汕头市| 咸宁市| 永寿县|