Spaces:
Sleeping
Sleeping
Upload 7 files
Browse files- .gitattributes +1 -0
- LICENSE +21 -0
- README.md +2 -13
- autoregressor_app.py +195 -0
- requirements.txt +8 -0
- training_1/checkpoint +2 -0
- training_1/cp.ckpt.data-00000-of-00001 +3 -0
- training_1/cp.ckpt.index +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
training_1/cp.ckpt.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
MIT License
|
2 |
+
|
3 |
+
Copyright (c) 2024 Kinshuk Gaurav, Charulkumar Chodvadiya
|
4 |
+
|
5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
+
of this software and associated documentation files (the "Software"), to deal
|
7 |
+
in the Software without restriction, including without limitation the rights
|
8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
+
copies of the Software, and to permit persons to whom the Software is
|
10 |
+
furnished to do so, subject to the following conditions:
|
11 |
+
|
12 |
+
The above copyright notice and this permission notice shall be included in all
|
13 |
+
copies or substantial portions of the Software.
|
14 |
+
|
15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21 |
+
SOFTWARE.
|
README.md
CHANGED
@@ -1,13 +1,2 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
emoji: 📊
|
4 |
-
colorFrom: pink
|
5 |
-
colorTo: green
|
6 |
-
sdk: streamlit
|
7 |
-
sdk_version: 1.38.0
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
license: mit
|
11 |
-
---
|
12 |
-
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
# Generative_playground
|
2 |
+
This repo. will the playground for the various generative models, to paly with.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
autoregressor_app.py
ADDED
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
import numpy as np
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
import pandas as pd
|
6 |
+
import seaborn as sns
|
7 |
+
import warnings
|
8 |
+
warnings.filterwarnings('ignore')
|
9 |
+
# %matplotlib inline
|
10 |
+
|
11 |
+
import tensorflow
|
12 |
+
print (tensorflow.__version__)
|
13 |
+
|
14 |
+
st.header("Welcome to the Generative Playground")
|
15 |
+
st.write("This is an autoregressor model on cifar10 data set, with 50 epochs and 16 batch size trained only. RTX GPU is used to train the model.")
|
16 |
+
|
17 |
+
from tensorflow.keras.datasets import mnist,cifar10
|
18 |
+
|
19 |
+
|
20 |
+
(trainX, trainy), (testX, testy) = cifar10.load_data()
|
21 |
+
|
22 |
+
print('Training data shapes: X=%s, y=%s' % (trainX.shape, trainy.shape))
|
23 |
+
print('Testing data shapes: X=%s, y=%s' % (testX.shape, testy.shape))
|
24 |
+
|
25 |
+
|
26 |
+
|
27 |
+
for k in range(4):
|
28 |
+
fig = plt.figure(figsize=(9,6))
|
29 |
+
for j in range(9):
|
30 |
+
i = np.random.randint(0, 10000)
|
31 |
+
plt.subplot(990 + 1 + j)
|
32 |
+
plt.imshow(trainX[i], cmap='gray_r')
|
33 |
+
# st.pyplot(fig)
|
34 |
+
plt.axis('off')
|
35 |
+
#plt.title(trainy[i])
|
36 |
+
plt.show()
|
37 |
+
st.pyplot(fig)
|
38 |
+
|
39 |
+
|
40 |
+
# asdfaf
|
41 |
+
|
42 |
+
trainX = np.where(trainX < (0.33 * 256), 0, 1)
|
43 |
+
train_data = trainX.astype(np.float32)
|
44 |
+
|
45 |
+
testX = np.where(testX < (0.33 * 256), 0, 1)
|
46 |
+
test_data = testX.astype(np.float32)
|
47 |
+
|
48 |
+
train_data = np.reshape(train_data, (50000, 32, 32, 3))
|
49 |
+
test_data = np.reshape(test_data, (10000, 32, 32, 3))
|
50 |
+
|
51 |
+
print (train_data.shape, test_data.shape)
|
52 |
+
|
53 |
+
|
54 |
+
import tensorflow
|
55 |
+
|
56 |
+
class PixelConvLayer(tensorflow.keras.layers.Layer):
|
57 |
+
def __init__(self, mask_type, **kwargs):
|
58 |
+
super(PixelConvLayer, self).__init__()
|
59 |
+
self.mask_type = mask_type
|
60 |
+
self.conv = tensorflow.keras.layers.Conv2D(**kwargs)
|
61 |
+
|
62 |
+
def build(self, input_shape):
|
63 |
+
# Build the conv2d layer to initialize kernel variables
|
64 |
+
self.conv.build(input_shape)
|
65 |
+
# Use the initialized kernel to create the mask
|
66 |
+
kernel_shape = self.conv.kernel.get_shape()
|
67 |
+
self.mask = np.zeros(shape=kernel_shape)
|
68 |
+
self.mask[: kernel_shape[0] // 2, ...] = 1.0
|
69 |
+
self.mask[kernel_shape[0] // 2, : kernel_shape[1] // 2, ...] = 1.0
|
70 |
+
if self.mask_type == "B":
|
71 |
+
self.mask[kernel_shape[0] // 2, kernel_shape[1] // 2, ...] = 1.0
|
72 |
+
|
73 |
+
def call(self, inputs):
|
74 |
+
self.conv.kernel.assign(self.conv.kernel * self.mask)
|
75 |
+
return self.conv(inputs)
|
76 |
+
|
77 |
+
|
78 |
+
# Next, we build our residual block layer.
|
79 |
+
# This is just a normal residual block, but based on the PixelConvLayer.
|
80 |
+
class ResidualBlock(tensorflow.keras.layers.Layer):
|
81 |
+
def __init__(self, filters, **kwargs):
|
82 |
+
super(ResidualBlock, self).__init__(**kwargs)
|
83 |
+
self.conv1 = tensorflow.keras.layers.Conv2D(
|
84 |
+
filters=filters, kernel_size=1, activation="relu"
|
85 |
+
)
|
86 |
+
self.pixel_conv = PixelConvLayer(
|
87 |
+
mask_type="B",
|
88 |
+
filters=filters // 2,
|
89 |
+
kernel_size=3,
|
90 |
+
activation="relu",
|
91 |
+
padding="same",
|
92 |
+
)
|
93 |
+
self.conv2 = tensorflow.keras.layers.Conv2D(
|
94 |
+
filters=filters, kernel_size=1, activation="relu"
|
95 |
+
)
|
96 |
+
|
97 |
+
def call(self, inputs):
|
98 |
+
x = self.conv1(inputs)
|
99 |
+
x = self.pixel_conv(x)
|
100 |
+
x = self.conv2(x)
|
101 |
+
return tensorflow.keras.layers.add([inputs, x])
|
102 |
+
|
103 |
+
inputs = tensorflow.keras.Input(shape=(32,32,3))
|
104 |
+
x = PixelConvLayer(
|
105 |
+
mask_type="A", filters=128, kernel_size=7, activation="relu", padding="same"
|
106 |
+
)(inputs)
|
107 |
+
|
108 |
+
for _ in range(5):
|
109 |
+
x = ResidualBlock(filters=128)(x)
|
110 |
+
|
111 |
+
for _ in range(2):
|
112 |
+
x = PixelConvLayer(
|
113 |
+
mask_type="B",
|
114 |
+
filters=128,
|
115 |
+
kernel_size=1,
|
116 |
+
strides=1,
|
117 |
+
activation="relu",
|
118 |
+
padding="valid",
|
119 |
+
)(x)
|
120 |
+
|
121 |
+
out = tensorflow.keras.layers.Conv2D(
|
122 |
+
filters=3, kernel_size=1, strides=1, activation="sigmoid", padding="valid"
|
123 |
+
)(x)
|
124 |
+
|
125 |
+
pixel_cnn = tensorflow.keras.Model(inputs, out)
|
126 |
+
pixel_cnn.summary()
|
127 |
+
|
128 |
+
adam = tensorflow.keras.optimizers.Adam(learning_rate=0.0005)
|
129 |
+
pixel_cnn.compile(optimizer=adam, loss="binary_crossentropy")
|
130 |
+
|
131 |
+
|
132 |
+
# %%
|
133 |
+
import os
|
134 |
+
checkpoint_path = "training_1/cp.ckpt"
|
135 |
+
checkpoint_dir = os.path.dirname(checkpoint_path)
|
136 |
+
|
137 |
+
|
138 |
+
pixel_cnn.load_weights(checkpoint_path)
|
139 |
+
|
140 |
+
|
141 |
+
# %% [markdown]
|
142 |
+
# # Display Results 81 images
|
143 |
+
|
144 |
+
# %%
|
145 |
+
#from IPython.display import Image, display
|
146 |
+
from tqdm import tqdm_notebook
|
147 |
+
|
148 |
+
|
149 |
+
# Create an empty array of pixels.
|
150 |
+
batch = 81
|
151 |
+
pixels = np.zeros(shape=(batch,) + (pixel_cnn.input_shape)[1:])
|
152 |
+
batch, rows, cols, channels = pixels.shape
|
153 |
+
|
154 |
+
print(pixels.shape)
|
155 |
+
|
156 |
+
|
157 |
+
import time
|
158 |
+
|
159 |
+
# progress_text = "Operation in progress. Please wait."
|
160 |
+
# my_bar = st.progress(0, progress_text)
|
161 |
+
st.caption("Generating..... pls.. wait.. :)")
|
162 |
+
my_bar = st.progress(0)
|
163 |
+
|
164 |
+
|
165 |
+
# Iterate over the pixels because generation has to be done sequentially pixel by pixel.
|
166 |
+
for row in range(rows):
|
167 |
+
for col in range(cols):
|
168 |
+
for channel in range(channels):
|
169 |
+
time.sleep(0.01)
|
170 |
+
# Feed the whole array and retrieving the pixel value probabilities for the next
|
171 |
+
# pixel.
|
172 |
+
probs = pixel_cnn.predict(pixels)[:, row, col, channel]
|
173 |
+
# Use the probabilities to pick pixel values and append the values to the image
|
174 |
+
# frame.
|
175 |
+
pixels[:, row, col, channel] = tensorflow.math.ceil(
|
176 |
+
probs - tensorflow.random.uniform(probs.shape)
|
177 |
+
)
|
178 |
+
my_bar.progress(row+1)
|
179 |
+
time.sleep(1)
|
180 |
+
|
181 |
+
counter = 0
|
182 |
+
for i in range(4):
|
183 |
+
figout = plt.figure(figsize=(9,6))
|
184 |
+
for j in range(9):
|
185 |
+
plt.subplot(990 + 1 + j)
|
186 |
+
plt.imshow(pixels[counter,:,:,0])#, cmap='gray_r')
|
187 |
+
counter += 1
|
188 |
+
plt.axis('off')
|
189 |
+
plt.show()
|
190 |
+
st.pyplot(figout)
|
191 |
+
|
192 |
+
# %%
|
193 |
+
|
194 |
+
|
195 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit == 1.9.2
|
2 |
+
numpy == 1.26.3
|
3 |
+
matplotlib == 3.8.2
|
4 |
+
pandas == 2.1.4
|
5 |
+
seaborn == 0.13.2
|
6 |
+
tensorflow == 2.9.0
|
7 |
+
tqdm == 4.66.2
|
8 |
+
|
training_1/checkpoint
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
model_checkpoint_path: "cp.ckpt"
|
2 |
+
all_model_checkpoint_paths: "cp.ckpt"
|
training_1/cp.ckpt.data-00000-of-00001
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a8e94392a9bd55fc21bcdd84bfce8909ac6f8c42ead8349f9b02dab23f5ebf1c
|
3 |
+
size 6564857
|
training_1/cp.ckpt.index
ADDED
Binary file (8.74 kB). View file
|
|