Tensors, layers और autoencoders

Keras के साथ डीप लर्निंग परिचय

Miguel Esteban

Data Scientist & Founder

Keras layers को access करना

# Keras मॉडल की पहली layer को access करना
first_layer = model.layers[0]

# layer, उसके input, output और weights प्रिंट करना print(first_layer.input) print(first_layer.output) print(first_layer.weights)
<tf.Tensor 'dense_1_input:0' shape=(?, 3) dtype=float32>
<tf.Tensor 'dense_1/Relu:0' shape=(?, 2) dtype=float32>
[<tf.Variable 'dense_1/kernel:0' shape=(3, 2) dtype=float32_ref>,
 <tf.Variable 'dense_1/bias:0' shape=(2,) dtype=float32_ref>]
Keras के साथ डीप लर्निंग परिचय

Tensors क्या हैं?

# rank 2 tensor (2 dimensions) परिभाषित करना
T2 = [[1,2,3],
      [4,5,6],
      [7,8,9]]

# rank 3 tensor (3 dimensions) परिभाषित करना T3 = [[1,2,3], [4,5,6], [7,8,9], [10,11,12], [13,14,15], [16,17,18], [19,20,21], [22,23,24], [25,26,27]]
Keras के साथ डीप लर्निंग परिचय
# Keras backend import करें
import tensorflow.keras.backend as K

# मॉडल की किसी layer के input और output tensors पाएँ inp = model.layers[0].input out = model.layers[0].output
# फ़ंक्शन जो layer inputs को outputs से मैप करता है inp_to_out = K.function([inp], [out])
# हम input पास करते हैं और उस पहली layer का output पाते हैं print(inp_to_out([X_train])
# X_train में प्रति sample पहली layer के outputs
[array([[0.7, 0],...,[0.1, 0.3]])]
Keras के साथ डीप लर्निंग परिचय

Keras के साथ डीप लर्निंग परिचय

Autoencoders!

Keras के साथ डीप लर्निंग परिचय

Autoencoders!

Keras के साथ डीप लर्निंग परिचय

Autoencoder उपयोग के मामले

  • Dimensionality reduction:
    • हमारे inputs का छोटे आयाम वाला प्रतिनिधित्व.
  • De-noising data:
    • यदि clean data पर train किया जाए, तो reconstruction के दौरान अनावश्यक noise फ़िल्टर हो जाएगा.
  • Anomaly detection:
    • अनदेखे inputs पर मॉडल का reconstruction कमज़ोर होगा.
  • ...

Keras के साथ डीप लर्निंग परिचय

एक सरल autoencoder बनाना

# एक sequential मॉडल instantiate करें
autoencoder = Sequential()

# 4 neurons की hidden layer और 100 की input layer जोड़ें autoencoder.add(Dense(4, input_shape=(100,), activation='relu'))
# 100 neurons की output layer जोड़ें autoencoder.add(Dense(100, activation='sigmoid'))
# उपयुक्त loss के साथ अपना मॉडल compile करें autoencoder.compile(optimizer='adam', loss='binary_crossentropy')
Keras के साथ डीप लर्निंग परिचय

इसे encoder में बाँटना

# inputs को encode करने के लिए अलग मॉडल बनाना
encoder = Sequential()
encoder.add(autoencoder.layers[0])

# Predict करने पर चार hidden layer neurons के outputs मिलते हैं encoder.predict(X_test)
# X_test की प्रत्येक observation के लिए चार संख्याएँ
array([10.0234375, 5.833543, 18.90444, 9.20348],...)
Keras के साथ डीप लर्निंग परिचय

चलो प्रयोग करें!

Keras के साथ डीप लर्निंग परिचय

Preparing Video For Download...