Importing libraries confusion

We imported libraries like this.

from tensorflow.keras.layers import Dense, Input
from tensorflow.keras import Sequential
from tensorflow.keras.losses import MeanSquaredError, BinaryCrossentropy
from tensorflow.keras.activations import sigmoid

What if, instead of writing individually we could also write

import tensorflow.keras as tks 

What’s the difference here? does it take much memory or another issue?

Hello @Tahmidul_Azom_Sany

Welcome to the community.

Yes, you could write it as:

import tensorflow.keras as tks

As an example if you want to invoke the Dense layer, at ALL times you would have to invoke it as:

tks.layers.Dense() instead of Dense()

To not have to carry around this alias with all the hierarchical class references ALL THE TIME, we import it as

from tensorflow.keras.layers import Dense, Input.

Since the hierarchical class references have been provided while importing the library, we can now directly invoke it as Dense()

1 Like