|
import random |
|
|
|
import matplotlib.pyplot as plt |
|
import pandas as pd |
|
from datasets import load_dataset, ClassLabel, Sequence |
|
import json |
|
import numpy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import streamlit as st |
|
from Data_Generation.Dataset_Generation_Functions import make_boxes |
|
|
|
|
|
x = st.slider('Select a value') |
|
st.write(x, 'squared is', x * x) |
|
|
|
|
|
''' |
|
# Testing |
|
image_size = 100 |
|
densities = [1] |
|
|
|
boxes = make_boxes(image_size, densities) |
|
|
|
desired_density = 1 |
|
# desired_thickness = 0 |
|
|
|
desired_basic_box_thickness = 1 |
|
desired_forward_slash_box_thickness = 2 |
|
desired_back_slash_box_thickness = 0 |
|
desired_hot_dog_box_thickness = 0 |
|
desired_hamburger_box_thickness = 0 |
|
|
|
|
|
box_arrays, box_density, basic_box_thickness, forward_slash_box_thickness, back_slash_box_thickness,hot_dog_box_thickness, hamburger_box_thickness\ |
|
= list(zip(*boxes))[0], list(zip(*boxes))[1], list(zip(*boxes))[2], list(zip(*boxes))[3], list(zip(*boxes))[4], list(zip(*boxes))[5], list(zip(*boxes))[6] |
|
# print(np.shape(box_arrays)) |
|
# print(np.shape(box_shape)) |
|
# print(np.shape(box_density)) |
|
|
|
indices = [i for i in range(len(box_arrays)) if box_density[i] == desired_density |
|
and basic_box_thickness[i] == desired_basic_box_thickness |
|
and forward_slash_box_thickness[i] == desired_forward_slash_box_thickness |
|
and back_slash_box_thickness[i] == desired_back_slash_box_thickness |
|
and hot_dog_box_thickness[i] == desired_hot_dog_box_thickness |
|
and hamburger_box_thickness[i] == desired_hamburger_box_thickness] |
|
plt.imshow(box_arrays[indices[0]], cmap='gray', vmin=0, vmax=1) |
|
plt.show() |
|
''' |
|
|
|
|
|
|
|
''' |
|
|
|
# food = load_dataset("cmudrc/2d-lattices", split="train[:15]") # Loads the training data samples |
|
food = load_dataset("cmudrc/2d-lattices", split="train+test") # Loads all of the data, for use after training |
|
|
|
# checks to see if the dataset has been assigned a class label |
|
# if type(food.features["label"]) != 'datasets.features.features.ClassLabel': # Cast to ClassLabel |
|
# food = food.class_encode_column('label') |
|
print(food) |
|
desired_label = 'x_plus_box' |
|
desired_thickness = 3 |
|
desired_density = 1 |
|
|
|
data_frame = pd.DataFrame(food) |
|
# print(data_frame) |
|
|
|
shape_rows = data_frame['Shape'] == desired_label |
|
# print(shape_rows) |
|
|
|
thickness_rows = data_frame['Thickness'] == desired_thickness |
|
# print(thickness_rows) |
|
|
|
density_rows = data_frame['Density'] == desired_density |
|
# print(density_rows) |
|
|
|
desired_output = data_frame.loc[shape_rows & thickness_rows & density_rows].iloc[0]['Array'] |
|
print(desired_output) |
|
print(type(desired_output)) |
|
|
|
|
|
example_point = numpy.array(json.loads(desired_output)) |
|
|
|
plt.imshow(example_point) |
|
plt.show() |
|
|
|
|
|
all_shapes = [basic_box, diagonal_box_split, horizontal_vertical_box_split, back_slash_box, forward_slash_box, |
|
back_slash_plus_box, forward_slash_plus_box, hot_dog_box, hamburger_box, x_hamburger_box, |
|
x_hot_dog_box, x_plus_box] |
|
|
|
base_shapes = [basic_box, back_slash_box, forward_slash_box, hot_dog_box, hamburger_box] |
|
image_size = 256 |
|
density = [1] |
|
|
|
boxes = make_boxes(image_size, density, all_shapes) |
|
|
|
|
|
box_arrays, box_shape, box_density, box_thickness, = list(zip(*boxes))[0], list(zip(*boxes))[1], list(zip(*boxes))[2], list(zip(*boxes))[3] |
|
|
|
# indices_1 = [i for i in range(len(boxes)) if boxes[1][i] == str(base_shapes[0]) and boxes[2][i] == density[0] and boxes[3][i] == desired_thickness] |
|
indices_1 = [i for i in range(len(box_arrays)) if box_shape[i] == desired_label and box_density[i] == desired_density and box_thickness[i] == desired_thickness] |
|
print(indices_1) |
|
# indices_1 = random.randint(0, len(box_arrays)) |
|
|
|
|
|
# plt.imshow(box_arrays[indices_1]) |
|
plt.imshow(box_arrays[indices_1[0]]) |
|
plt.show() |
|
''' |
|
|
|
'''trainer.push_to_hub()''' |