def init_resnet(hparams, model):
    'Init resnet weights from a TF model if provided.'
    if (not hparams['widget_encoder_checkpoint']):
        return
    reader = tf.train.load_checkpoint(hparams['widget_encoder_checkpoint'])
    init_set = input_utils.input_fn(hparams['train_files'], 1, hparams['vocab_size'], hparams['max_pixel_pos'], hparams['max_dom_pos'], epoches=1, buffer_size=1)
    init_features = next(iter(init_set))
    init_target = model.compute_targets(init_features)
    model([init_features, init_target[0]], training=True)
    weight_value_tuples = []
    for layer in model._encoder._pixel_layers:
        for param in layer.weights:
            if ('batch_normalization' in param.name):
                continue
            (sublayer, varname) = param.name.replace(':0', '').split('/')[(- 2):]
            var_name = 'encoder/{}/{}'.format(sublayer, varname)
            if reader.has_tensor(var_name):
                logging.info('Found pretrained weights: %s %s, %s %s', param.name, param.shape, var_name, reader.get_tensor(var_name).shape)
                weight_value_tuples.append((param, reader.get_tensor(var_name)))
    logging.info('Load pretrained %s weights', len(weight_value_tuples))
    tf.keras.backend.batch_set_value(weight_value_tuples)
Init resnet weights from a TF model if provided.
def init_resnet(hparams, model):
    
    if (not hparams['widget_encoder_checkpoint']):
        return
    reader = tf.train.load_checkpoint(hparams['widget_encoder_checkpoint'])
    init_set = input_utils.input_fn(hparams['train_files'], 1, hparams['vocab_size'], hparams['max_pixel_pos'], hparams['max_dom_pos'], epoches=1, buffer_size=1)
    init_features = next(iter(init_set))
    init_target = model.compute_targets(init_features)
    model([init_features, init_target[0]], training=True)
    weight_value_tuples = []
    for layer in model._encoder._pixel_layers:
        for param in layer.weights:
            if ('batch_normalization' in param.name):
                continue
            (sublayer, varname) = param.name.replace(':0', ).split('/')[(- 2):]
            var_name = 'encoder/{}/{}'.format(sublayer, varname)
            if reader.has_tensor(var_name):
                logging.info('Found pretrained weights: %s %s, %s %s', param.name, param.shape, var_name, reader.get_tensor(var_name).shape)
                weight_value_tuples.append((param, reader.get_tensor(var_name)))
    logging.info('Load pretrained %s weights', len(weight_value_tuples))
    tf.keras.backend.batch_set_value(weight_value_tuples)