Tawsif
Tawsif

Reputation: 15

Why can't I access the keras.initializers class?

I'm trying to use the HeUniform() method from the keras.initializers class, bu when I go to run my code, I get the following output:

AttributeError: module 'tensorflow_core.keras.initializers' has no attribute 'HeUniform'

The code that I ran is the following:

init = tf.keras.initializers.HeUniform()

My imports are:

import gym
import tensorflow as tf
import numpy as np
from tensorflow import keras

from collections import deque
import time
import random

I'm using tensorflow version 2.0.0 installed from conda. I tried to upgrade the version, but I was getting further errors saying that version 2.2.0 and 2.4.1 does not exist for conda. Please advise.

Upvotes: 1

Views: 1507

Answers (1)

jkr
jkr

Reputation: 19310

Take a look at the tensorflow api documentation for version 2.0. There is no class tf.keras.initializers.HeUniform. Instead, there is a function tf.keras.initializers.he_uniform. You can find the source code for the function on GitHub.

TensorFlow recommends installing with pip. In the past, I have created a new conda environment specifically for tensorflow. It is bad practice to mix conda and pip packages, so that's why I create a new environment just for the specific version of tensorflow.

conda create -n tf2 python=3.8
conda activate tf2
python -m pip install --no-cache-dir tensorflow==2.4.1

Just keep in mind that the GPU versions depend on specific versions of CUDA and cuDNN. See https://www.tensorflow.org/install/source#gpu for more information about the requirements.

Upvotes: 2

Related Questions