Spaces:
Sleeping
Sleeping
Upload 9 files
Browse files- .gitattributes +37 -0
- README.md +13 -0
- app.py +239 -0
- requirements.txt +9 -0
- training_1/checkpoint +2 -0
- training_1/cp.ckpt.data-00000-of-00001 +3 -0
- training_1/cp.ckpt.index +0 -0
- training_1/cp.weights.h5 +3 -0
- training_1/state.db +3 -0
.gitattributes
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz 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
|
37 |
+
training_1/state.db filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Generative Playground
|
3 |
+
emoji: 🔥
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: pink
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.36.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
|
app.py
ADDED
@@ -0,0 +1,239 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
16 |
+
from tensorflow.keras.datasets import mnist,cifar10
|
17 |
+
|
18 |
+
option = st.selectbox(
|
19 |
+
"Which model would you like to get prediction with?",
|
20 |
+
("None","Auto-Regressor", "Auto-Encoder", "Diffusion-Model","Other"))
|
21 |
+
|
22 |
+
st.write("You selected:", option)
|
23 |
+
|
24 |
+
if option == "None":
|
25 |
+
st.write("Please Select the model to get the fun prediction.... :)")
|
26 |
+
|
27 |
+
if option == "Auto-Encoder":
|
28 |
+
st.write("It is under development")
|
29 |
+
st.write("Stay tune... Comming soon... :)")
|
30 |
+
|
31 |
+
if option == "Other":
|
32 |
+
st.write("Stay tune... Updating soon... :)")
|
33 |
+
|
34 |
+
if option == "Diffusion-Model":
|
35 |
+
st.write("It is under development")
|
36 |
+
st.write("Stay tune... Comming soon... :)")
|
37 |
+
|
38 |
+
if option == "Auto-Regressor":
|
39 |
+
if st.button("Run"):
|
40 |
+
st.write("Running Auto-Regressor")
|
41 |
+
|
42 |
+
st.write("trained on --> cifar-10 dataset, RTX-GPU's, 50-epochs")
|
43 |
+
st.write("This is trail model, updated version will be updated consicutively.")
|
44 |
+
|
45 |
+
(trainX, trainy), (testX, testy) = cifar10.load_data()
|
46 |
+
|
47 |
+
print('Training data shapes: X=%s, y=%s' % (trainX.shape, trainy.shape))
|
48 |
+
print('Testing data shapes: X=%s, y=%s' % (testX.shape, testy.shape))
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
for k in range(4):
|
53 |
+
fig = plt.figure(figsize=(9,6))
|
54 |
+
for j in range(9):
|
55 |
+
i = np.random.randint(0, 10000)
|
56 |
+
plt.subplot(990 + 1 + j)
|
57 |
+
plt.imshow(trainX[i], cmap='gray_r')
|
58 |
+
# st.pyplot(fig)
|
59 |
+
plt.axis('off')
|
60 |
+
#plt.title(trainy[i])
|
61 |
+
plt.show()
|
62 |
+
st.pyplot(fig)
|
63 |
+
|
64 |
+
|
65 |
+
# asdfaf
|
66 |
+
|
67 |
+
trainX = np.where(trainX < (0.33 * 256), 0, 1)
|
68 |
+
train_data = trainX.astype(np.float32)
|
69 |
+
|
70 |
+
testX = np.where(testX < (0.33 * 256), 0, 1)
|
71 |
+
test_data = testX.astype(np.float32)
|
72 |
+
|
73 |
+
train_data = np.reshape(train_data, (50000, 32, 32, 3))
|
74 |
+
test_data = np.reshape(test_data, (10000, 32, 32, 3))
|
75 |
+
|
76 |
+
print (train_data.shape, test_data.shape)
|
77 |
+
|
78 |
+
|
79 |
+
import tensorflow
|
80 |
+
|
81 |
+
class PixelConvLayer(tensorflow.keras.layers.Layer):
|
82 |
+
def __init__(self, mask_type, **kwargs):
|
83 |
+
super(PixelConvLayer, self).__init__()
|
84 |
+
self.mask_type = mask_type
|
85 |
+
self.conv = tensorflow.keras.layers.Conv2D(**kwargs)
|
86 |
+
|
87 |
+
def build(self, input_shape):
|
88 |
+
# Build the conv2d layer to initialize kernel variables
|
89 |
+
self.conv.build(input_shape)
|
90 |
+
# Use the initialized kernel to create the mask
|
91 |
+
kernel_shape = self.conv.kernel.get_shape()
|
92 |
+
self.mask = np.zeros(shape=kernel_shape)
|
93 |
+
self.mask[: kernel_shape[0] // 2, ...] = 1.0
|
94 |
+
self.mask[kernel_shape[0] // 2, : kernel_shape[1] // 2, ...] = 1.0
|
95 |
+
if self.mask_type == "B":
|
96 |
+
self.mask[kernel_shape[0] // 2, kernel_shape[1] // 2, ...] = 1.0
|
97 |
+
|
98 |
+
def call(self, inputs):
|
99 |
+
self.conv.kernel.assign(self.conv.kernel * self.mask)
|
100 |
+
return self.conv(inputs)
|
101 |
+
|
102 |
+
|
103 |
+
# Next, we build our residual block layer.
|
104 |
+
# This is just a normal residual block, but based on the PixelConvLayer.
|
105 |
+
class ResidualBlock(tensorflow.keras.layers.Layer):
|
106 |
+
def __init__(self, filters, **kwargs):
|
107 |
+
super(ResidualBlock, self).__init__(**kwargs)
|
108 |
+
self.conv1 = tensorflow.keras.layers.Conv2D(
|
109 |
+
filters=filters, kernel_size=1, activation="relu"
|
110 |
+
)
|
111 |
+
self.pixel_conv = PixelConvLayer(
|
112 |
+
mask_type="B",
|
113 |
+
filters=filters // 2,
|
114 |
+
kernel_size=3,
|
115 |
+
activation="relu",
|
116 |
+
padding="same",
|
117 |
+
)
|
118 |
+
self.conv2 = tensorflow.keras.layers.Conv2D(
|
119 |
+
filters=filters, kernel_size=1, activation="relu"
|
120 |
+
)
|
121 |
+
|
122 |
+
def call(self, inputs):
|
123 |
+
x = self.conv1(inputs)
|
124 |
+
x = self.pixel_conv(x)
|
125 |
+
x = self.conv2(x)
|
126 |
+
return tensorflow.keras.layers.add([inputs, x])
|
127 |
+
|
128 |
+
inputs = tensorflow.keras.Input(shape=(32,32,3))
|
129 |
+
x = PixelConvLayer(
|
130 |
+
mask_type="A", filters=128, kernel_size=7, activation="relu", padding="same"
|
131 |
+
)(inputs)
|
132 |
+
|
133 |
+
for _ in range(5):
|
134 |
+
x = ResidualBlock(filters=128)(x)
|
135 |
+
|
136 |
+
for _ in range(2):
|
137 |
+
x = PixelConvLayer(
|
138 |
+
mask_type="B",
|
139 |
+
filters=128,
|
140 |
+
kernel_size=1,
|
141 |
+
strides=1,
|
142 |
+
activation="relu",
|
143 |
+
padding="valid",
|
144 |
+
)(x)
|
145 |
+
|
146 |
+
out = tensorflow.keras.layers.Conv2D(
|
147 |
+
filters=3, kernel_size=1, strides=1, activation="sigmoid", padding="valid"
|
148 |
+
)(x)
|
149 |
+
|
150 |
+
pixel_cnn = tensorflow.keras.Model(inputs, out)
|
151 |
+
pixel_cnn.summary()
|
152 |
+
|
153 |
+
adam = tensorflow.keras.optimizers.Adam(learning_rate=0.0005)
|
154 |
+
pixel_cnn.compile(optimizer=adam, loss="binary_crossentropy")
|
155 |
+
|
156 |
+
|
157 |
+
# %%
|
158 |
+
import os
|
159 |
+
checkpoint_path = "training_1/cp.ckpt"
|
160 |
+
# checkpoint_path = "training_1/cp.weights.h5"
|
161 |
+
checkpoint_dir = os.path.dirname(checkpoint_path)
|
162 |
+
|
163 |
+
|
164 |
+
pixel_cnn.load_weights(checkpoint_path)
|
165 |
+
|
166 |
+
|
167 |
+
# %% [markdown]
|
168 |
+
# # Display Results 81 images
|
169 |
+
|
170 |
+
# %%
|
171 |
+
# from IPython.display import Image, display
|
172 |
+
from tqdm import tqdm
|
173 |
+
|
174 |
+
|
175 |
+
# Create an empty array of pixels.
|
176 |
+
batch = 1
|
177 |
+
pixels = np.zeros(shape=(batch,) + (pixel_cnn.input_shape)[1:])
|
178 |
+
batch, rows, cols, channels = pixels.shape
|
179 |
+
|
180 |
+
print(pixels.shape)
|
181 |
+
|
182 |
+
|
183 |
+
import time
|
184 |
+
|
185 |
+
# progress_text = "Operation in progress. Please wait."
|
186 |
+
# my_bar = st.progress(0, progress_text)
|
187 |
+
st.caption("Generating..... pls.. wait.. :)")
|
188 |
+
my_bar = st.progress(0)
|
189 |
+
|
190 |
+
|
191 |
+
# Iterate over the pixels because generation has to be done sequentially pixel by pixel.
|
192 |
+
for row in tqdm(range(rows)):
|
193 |
+
for col in range(cols):
|
194 |
+
for channel in range(channels):
|
195 |
+
time.sleep(0.01)
|
196 |
+
# Feed the whole array and retrieving the pixel value probabilities for the next
|
197 |
+
# pixel.
|
198 |
+
probs = pixel_cnn.predict(pixels)[:, row, col, channel]
|
199 |
+
# Use the probabilities to pick pixel values and append the values to the image
|
200 |
+
# frame.
|
201 |
+
pixels[:, row, col, channel] = tensorflow.math.ceil(
|
202 |
+
probs - tensorflow.random.uniform(probs.shape)
|
203 |
+
)
|
204 |
+
my_bar.progress(int(row*3.125))
|
205 |
+
# if row<rows/2:
|
206 |
+
# my_bar.progress((rows+1)*2)
|
207 |
+
# else:
|
208 |
+
# my_bar.progress(row+51)
|
209 |
+
|
210 |
+
my_bar.progress(100)
|
211 |
+
time.sleep(1)
|
212 |
+
|
213 |
+
|
214 |
+
from PIL import Image
|
215 |
+
# figout = plt.figure(figsize=(9,6))
|
216 |
+
# st.image(Image.fromarray((pixels[-1] * 255).astype(np.uint8), 'RGB').show(),caption="image")
|
217 |
+
# Convert the generated pixel array to an image
|
218 |
+
generated_image = Image.fromarray((pixels[-1] * 255).astype(np.uint8), 'RGB')
|
219 |
+
|
220 |
+
# Display the image using Streamlit
|
221 |
+
st.image(generated_image, caption="Generated Image")
|
222 |
+
|
223 |
+
# counter = 0
|
224 |
+
# for i in range(4):
|
225 |
+
# figout = plt.figure(figsize=(9,6))
|
226 |
+
# for j in range(9):
|
227 |
+
# plt.subplot(990 + 1 + j)
|
228 |
+
# plt.imshow(pixels[counter,:,:,0])#, cmap='gray_r')
|
229 |
+
# counter += 1
|
230 |
+
# plt.axis('off')
|
231 |
+
# plt.show()
|
232 |
+
# st.pyplot(figout)
|
233 |
+
|
234 |
+
# %%
|
235 |
+
# else:
|
236 |
+
# st.write("Not Available")
|
237 |
+
|
238 |
+
|
239 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
protobuf == 3.20.3
|
8 |
+
|
9 |
+
|
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
|
|
training_1/cp.weights.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3a9d0878b5a8409be8f7c5c75520f7afb1c8bc34b4696acf8e5e8a9bb4535365
|
3 |
+
size 6653656
|
training_1/state.db
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:817878e3f8d7d71333f53bfdd3e076ca595dc455f125c9ab55e0c2bbcd9dac67
|
3 |
+
size 2211959020
|