google-research

Форк
0
46 строк · 1.4 Кб
1
# coding=utf-8
2
# Copyright 2024 The Google Research Authors.
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15

16
"""Implementations of different initialization methods."""
17

18
import numpy as np
19
import tensorflow.compat.v1 as tf
20

21

22
def uniform(shape, scale=0.05, name=None):
23
  """Uniform init."""
24
  initial = tf.random_uniform(
25
      shape, minval=-scale, maxval=scale, dtype=tf.float32)
26
  return tf.Variable(initial, name=name)
27

28

29
def glorot(shape, name=None):
30
  """Glorot & Bengio (AISTATS 2010) init."""
31
  init_range = np.sqrt(6.0 / (shape[0] + shape[1]))
32
  initial = tf.random_uniform(
33
      shape, minval=-init_range, maxval=init_range, dtype=tf.float32)
34
  return tf.Variable(initial, name=name)
35

36

37
def zeros(shape, name=None):
38
  """All zeros."""
39
  initial = tf.zeros(shape, dtype=tf.float32)
40
  return tf.Variable(initial, name=name)
41

42

43
def ones(shape, name=None):
44
  """All ones."""
45
  initial = tf.ones(shape, dtype=tf.float32)
46
  return tf.Variable(initial, name=name)
47

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.