Igor2004 commited on
Commit
4f65a7c
·
1 Parent(s): 92d1bd0

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """Zadanie4_Semenov_II_DRPK47.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/11fNvzrVniDSjEVdE-ZnejpPvvA88ApfY
8
+ """
9
+
10
+ import numpy as np
11
+ import matplotlib.pyplot as plt
12
+ import tensorflow.keras as keras
13
+ import tensorflow.keras.datasets
14
+ from tensorflow.keras.datasets import fashion_mnist
15
+ from tensorflow.keras.layers import Input, Dense
16
+
17
+ (train_x, train_y), (test_x, test_y) = fashion_mnist.load_data()
18
+
19
+ train_x = train_x / 255
20
+ test_x = test_x / 255
21
+
22
+ train_x = np.reshape(train_x, (len(train_x), 28 * 28))
23
+ test_x = np.reshape(test_x, (len(test_x), 28 * 28))
24
+
25
+ inputs = Input(shape = (28*28, ))
26
+ x = Dense(150, activation = 'relu')(inputs)
27
+ x = Dense(400, activation = 'relu')(x)
28
+ x = Dense(10, activation = 'relu')(x)
29
+ encoder = Dense(3, activation = 'linear')(x)
30
+
31
+
32
+ inputs_dec = Input(shape = (3, ))
33
+ x = Dense(10, activation = 'relu')(inputs_dec)
34
+ x = Dense(40, activation = 'relu')(x)
35
+ x = Dense(150, activation = 'relu')(x)
36
+ decoder = Dense(28*28, activation = 'relu')(x)
37
+
38
+ encoder_model = keras.Model(inputs, encoder)
39
+ decoder_model = keras.Model(inputs_dec, decoder)
40
+ autoenc = keras.Model(inputs, decoder_model(encoder_model(inputs)))
41
+
42
+ autoenc.compile(optimizer='adam', loss='mean_squared_error', metrics = ['accuracy'])
43
+
44
+ autoenc.fit(train_x, train_x, epochs = 20, batch_size=50)
45
+
46
+ y = autoenc.predict(test_x[:12])
47
+ plt.imshow(y[5].reshape(28, 28), cmap = 'gray')