Spaces:
Build error
Build error
Jakub Kwiatkowski
commited on
Commit
·
758ad23
1
Parent(s):
6e28f48
Change properties.
Browse files- _.py +14 -0
- app.py +9 -8
- models.py +24 -9
- models_2.py +0 -22
- raven_utils/draw.py +2 -1
- utils.py +6 -6
_.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
start_image = 12000
|
4 |
+
|
5 |
+
from tensorflow.keras.models import load_model
|
6 |
+
model = load_model("saved_model/1")
|
7 |
+
|
8 |
+
from data_utils import nload, ims, DataSetFromFolder
|
9 |
+
data = nload("/home/jkwiatkowski/all/dataset/arr/val.npy")
|
10 |
+
indexes = nload("/home/jkwiatkowski/all/dataset/arr/val_target.npy")
|
11 |
+
|
12 |
+
folders = DataSetFromFolder("/home/jkwiatkowski/all/dataset/arr/RAVEN-10000-release/RAVEN-10000", file_type="dir")
|
13 |
+
properties = DataSetFromFolder(folders[:], file_type="xml", extension="val")
|
14 |
+
|
app.py
CHANGED
@@ -6,13 +6,13 @@ demo = gr.Blocks()
|
|
6 |
import models
|
7 |
|
8 |
with demo:
|
9 |
-
headline = gr.Markdown("## Raven resolver ")
|
10 |
-
markdown = gr.Markdown("Below we show all 9 images from raven matrix. "
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
with gr.Row():
|
17 |
with gr.Column():
|
18 |
with gr.Row():
|
@@ -25,7 +25,8 @@ with demo:
|
|
25 |
# button = gr.Button("Run")
|
26 |
with gr.Row():
|
27 |
image = gr.Image(value=load_example(models.START_IMAGE)[0], label="Raven matrix")
|
28 |
-
desc = gr.Markdown(value=load_example(models.START_IMAGE)[1])
|
|
|
29 |
|
30 |
with gr.Column():
|
31 |
with gr.Row():
|
|
|
6 |
import models
|
7 |
|
8 |
with demo:
|
9 |
+
# headline = gr.Markdown("## Raven resolver ")
|
10 |
+
# markdown = gr.Markdown("Below we show all 9 images from raven matrix. "
|
11 |
+
# "Model gets 8 images and predicts the properties of last one. "
|
12 |
+
# "Based on this properties the answer image is render in the right panel. <br />"
|
13 |
+
# "Note that angle rotation is only used as a noise. "
|
14 |
+
# "There are not rules applied to angle property, so angle rotation of final output do not need to be the same as in example. "
|
15 |
+
# "Additionally there are cases that other properties could be used as noise.")
|
16 |
with gr.Row():
|
17 |
with gr.Column():
|
18 |
with gr.Row():
|
|
|
25 |
# button = gr.Button("Run")
|
26 |
with gr.Row():
|
27 |
image = gr.Image(value=load_example(models.START_IMAGE)[0], label="Raven matrix")
|
28 |
+
# desc = gr.Markdown(value=load_example(models.START_IMAGE)[1])
|
29 |
+
desc = gr.Text(value=load_example(models.START_IMAGE)[1])
|
30 |
|
31 |
with gr.Column():
|
32 |
with gr.Row():
|
models.py
CHANGED
@@ -1,14 +1,29 @@
|
|
1 |
-
import
|
|
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
model =
|
|
|
|
|
|
|
7 |
|
8 |
-
from data_utils import nload, ims, DataSetFromFolder
|
9 |
-
data = nload("/home/jkwiatkowski/all/dataset/arr/val.npy")
|
10 |
-
indexes = nload("/home/jkwiatkowski/all/dataset/arr/val_target.npy")
|
11 |
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
from config_utils import tf_gpu
|
3 |
+
from data_utils import DataSetFromFolder
|
4 |
|
5 |
+
tf_gpu()
|
6 |
+
tf.experimental.numpy.experimental_enable_numpy_behavior(prefer_float32=True)
|
7 |
+
|
8 |
+
from huggingface_hub import from_pretrained_keras
|
9 |
+
from datasets import load_dataset
|
10 |
+
|
11 |
+
repo = "jkwiatkowski/raven"
|
12 |
|
13 |
+
data = load_dataset(repo, split="val")
|
14 |
+
model = from_pretrained_keras(repo)
|
15 |
+
|
16 |
+
properties = load_dataset(repo + "_properties", split="val")
|
17 |
+
START_IMAGE = 12000
|
18 |
|
|
|
|
|
|
|
19 |
|
20 |
+
# def convert(data):
|
21 |
+
# return {
|
22 |
+
# 'inputs': tf.cast(data['inputs'], dtype="uint8"),
|
23 |
+
# 'index': tf.cast(data['index'], dtype="uint8")[..., None],
|
24 |
+
# 'target': tf.cast(data['target'], dtype="int8"),
|
25 |
+
# }
|
26 |
+
#
|
27 |
+
# model(convert(data[0:1]))
|
28 |
|
29 |
+
print("xD")
|
models_2.py
DELETED
@@ -1,22 +0,0 @@
|
|
1 |
-
import tensorflow as tf
|
2 |
-
from config_utils import tf_gpu
|
3 |
-
tf_gpu()
|
4 |
-
tf.experimental.numpy.experimental_enable_numpy_behavior(prefer_float32=True)
|
5 |
-
|
6 |
-
from huggingface_hub import from_pretrained_keras
|
7 |
-
from datasets import load_dataset
|
8 |
-
|
9 |
-
data = load_dataset("jkwiatkowski/raven", split="val")
|
10 |
-
model = from_pretrained_keras("jkwiatkowski/raven")
|
11 |
-
|
12 |
-
def convert(data):
|
13 |
-
return {
|
14 |
-
'inputs': tf.cast(data['inputs'], dtype="uint8"),
|
15 |
-
'index': tf.cast(data['index'], dtype="uint8"),
|
16 |
-
'target': tf.cast(data['target'], dtype="int8"),
|
17 |
-
}
|
18 |
-
|
19 |
-
print("xD")
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
raven_utils/draw.py
CHANGED
@@ -5,6 +5,7 @@ from funcy import identity
|
|
5 |
from ml_utils import none, filter_keys, lu
|
6 |
from models_utils import is_model
|
7 |
from models_utils import ops as K
|
|
|
8 |
|
9 |
from raven_utils.constant import PROPERTY, TARGET, INPUTS
|
10 |
from raven_utils.decode import decode_target, target_mask
|
@@ -65,7 +66,7 @@ def val_sample(generator, no=1, indexes=None):
|
|
65 |
|
66 |
def render_from_model(data,predict,pre_fn=identity):
|
67 |
data = filter_keys(data, PROPERTY, reverse=True)
|
68 |
-
if is_model(predict):
|
69 |
predict = predict(data)
|
70 |
pro = np.array(target_mask(predict['predict_mask'].numpy()) * predict["predict"].numpy(), dtype=np.int8)
|
71 |
return pre_fn(render_panels(pro, target=False)[None])[0]
|
|
|
5 |
from ml_utils import none, filter_keys, lu
|
6 |
from models_utils import is_model
|
7 |
from models_utils import ops as K
|
8 |
+
from tensorflow.python.saved_model.load import Loader
|
9 |
|
10 |
from raven_utils.constant import PROPERTY, TARGET, INPUTS
|
11 |
from raven_utils.decode import decode_target, target_mask
|
|
|
66 |
|
67 |
def render_from_model(data,predict,pre_fn=identity):
|
68 |
data = filter_keys(data, PROPERTY, reverse=True)
|
69 |
+
if is_model(predict) or str(type(predict)) == "<class 'tensorflow.python.saved_model.load.Loader._recreate_base_user_object.<locals>._UserObject'>":
|
70 |
predict = predict(data)
|
71 |
pro = np.array(target_mask(predict['predict_mask'].numpy()) * predict["predict"].numpy(), dtype=np.int8)
|
72 |
return pre_fn(render_panels(pro, target=False)[None])[0]
|
utils.py
CHANGED
@@ -20,10 +20,12 @@ def load_example(index=0):
|
|
20 |
index = 0
|
21 |
index = int(index)
|
22 |
|
23 |
-
desc =
|
24 |
-
desc = "<br /><br />".join(["<br />".join(d) for d in desc])
|
25 |
|
26 |
-
example = get_matrix(
|
|
|
|
|
|
|
27 |
result = np.tile(draw_images(example[:9], row=3), reps=(1, 1, 3))
|
28 |
return result, desc
|
29 |
|
@@ -46,15 +48,13 @@ def run_nn(index=0):
|
|
46 |
if not index:
|
47 |
index = models.START_IMAGE
|
48 |
index = int(index)
|
49 |
-
data = models.data[index:index + 1]
|
50 |
|
51 |
# model = load_model("/home/jkwiatkowski/all/best/rav/full_trans/6e8e6bad403e4171ad10daa1a518ba09")
|
52 |
data = {
|
53 |
'inputs': data,
|
54 |
'index': np.zeros(shape=(1, 1), dtype="uint8"),
|
55 |
-
'labels': np.zeros(shape=(1, 16, 113), dtype="int8"),
|
56 |
'target': np.zeros(shape=(1, 16, 113), dtype="int8"),
|
57 |
-
# 'features': np.zeros(shape=(1, 16, 64), dtype="float32")
|
58 |
}
|
59 |
res = np.tile(render_from_model(data, models.model)[0, ..., None], reps=(1, 1, 3))
|
60 |
|
|
|
20 |
index = 0
|
21 |
index = int(index)
|
22 |
|
23 |
+
desc = models.properties[index]['Description']
|
|
|
24 |
|
25 |
+
example = get_matrix(
|
26 |
+
np.array(models.data[index:index + 1]['inputs'], dtype="uint8"),
|
27 |
+
np.array(models.data[index:index + 1]['index'], dtype="uint8")[..., None]
|
28 |
+
)
|
29 |
result = np.tile(draw_images(example[:9], row=3), reps=(1, 1, 3))
|
30 |
return result, desc
|
31 |
|
|
|
48 |
if not index:
|
49 |
index = models.START_IMAGE
|
50 |
index = int(index)
|
51 |
+
data = models.data[index:index + 1]['inputs']
|
52 |
|
53 |
# model = load_model("/home/jkwiatkowski/all/best/rav/full_trans/6e8e6bad403e4171ad10daa1a518ba09")
|
54 |
data = {
|
55 |
'inputs': data,
|
56 |
'index': np.zeros(shape=(1, 1), dtype="uint8"),
|
|
|
57 |
'target': np.zeros(shape=(1, 16, 113), dtype="int8"),
|
|
|
58 |
}
|
59 |
res = np.tile(render_from_model(data, models.model)[0, ..., None], reps=(1, 1, 3))
|
60 |
|