<jupyter_start><jupyter_text>data function<jupyter_code>def YtoArr(y):
    arr = []
    for i in y:
        tmp = []
        for j in range(25):
            if (int(i/10) == j) :
                tmp.append(1)
            else :
                tmp.append(0)
        arr.append(tmp)
    return arr

def get_XY_from_image(photo_name:str,color:int,jumps:int=100,show:bool=False):
    data = asarray(Image.open(photo_name))
    color_arr = data[:,:,color]
    image_color_arr = Image.fromarray(color_arr)
    if show: image_color_arr.show()
    data_x = []
    data_y = []
    print(f"pic size: {len(color_arr)}x{len(color_arr[0])} name: {photo_name}")
    for i in range(1,len(color_arr)-1,jumps):
        for j in range(1,len(color_arr[0])-1):
            temp_y = [color_arr[i][j]]
            temp_x = [color_arr[i-1][j-1],color_arr[i-1][j],color_arr[i][j-1],color_arr[i+1][j],color_arr[i][j+1],color_arr[i+1][j+1],color_arr[i-1][j+1],color_arr[i+1][j-1]]
            data_y.append(temp_y)
            data_x.append(temp_x)
    return (data_x,data_y)

def load_pic_data(pics_array,color:int,jumps:int=100,show:bool=False):
    data_x , data_y = get_XY_from_image(pics_array[0],color,jumps,show)
    for i in pics_array[1:]:
        data_tmp_x , data_tmp_y = get_XY_from_image(i,color,jumps,show)
        data_x = np.append(data_x,data_tmp_x,axis=0)
        data_y = np.append(data_y,data_tmp_y,axis=0)
    data_x = np.array(data_x)
    data_y = np.array(data_y)
    return data_x,data_y<jupyter_output><empty_output><jupyter_text>data<jupyter_code>data_x , data_y = load_pic_data(
    ["data/cat_test.jpg", "data/balloon.jpg","data/cat.jpg","data/city.jpg",
    "data/city_night.jpg","data/city_color.jpg",
    "data/flower.jpg"],
    color=0,jumps=100)
data_t_x , data_t_y = load_pic_data(["data/park.jpg"],color=1,jumps=100)
# print(data_t_y)
# print(YtoArr(data_t_y))
data_y = YtoArr(data_y)
data_t_y = YtoArr(data_t_y)

sess = tf.Session()
sess.run(tf.global_variables_initializer())

show = 10
loss_in_time = []
w_arr = []
w2_arr = []
test_over_time = []
accuracy_over_time = []

correct_prediction = tf.equal(tf.argmax(pred,1), tf.argmax(y,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

for i in range(0,10000):
       sess.run(update, feed_dict = {x:data_x, y:data_y})
       if(i%show==0 and i>21):
              tmp = sess.run(loss,feed_dict={x:data_x,y:data_y})
              loss_in_time.append(tmp)
              w_arr.append(sess.run(w1))
              w2_arr.append(sess.run(w2))
              if(i%(show*1)==0):
                     print(f"i = {i}, loss = {tmp},")
              accuracy_over_time.append(sess.run(accuracy, feed_dict={x:data_t_x,y:data_t_y}))
              test_over_time.append(sess.run(loss,feed_dict={x:data_t_x,y:data_t_y}))



d = np.array(np.array(w_arr).transpose()[0]).transpose()
plt.plot(d)
plt.ylabel('w1 over time')
plt.show()

d = np.array(np.array(w2_arr).transpose()[0]).transpose()
plt.plot(d)
plt.ylabel('w2 over time')
plt.show()

plt.plot(loss_in_time,label ="loss")
plt.plot(test_over_time , label ="test")
plt.legend()
plt.ylabel('loss over time')
plt.show()

plt.plot(accuracy_over_time,label ="accuracy over time")
plt.legend()
plt.ylabel('accuracy over time')
plt.show()
picR,y_data = load_pic_data(["data/cat.jpg"],color=0,jumps=1)
picG,y_data = load_pic_data(["data/cat.jpg"],color=1,jumps=1)
picB,y_data = load_pic_data(["data/cat.jpg"],color=2,jumps=1)
pR = sess.run(pred,feed_dict={x:picR})
pG = sess.run(pred,feed_dict={x:picG})
pB = sess.run(pred,feed_dict={x:picB})
# print(p)
def YtoPic(arr):
    picture = []
    for line in arr:
        max_pos = 0
        tmp_max = 0
        for i,num in enumerate(line):
            if(num>tmp_max):
                max_pos = i
                tmp_max = num
        color_tmp = max_pos*10
        picture.append(color_tmp)
    return picture
pictureR = YtoPic(pR)
pictureG = YtoPic(pG)
pictureB = YtoPic(pB)
size_x = 576
size_y = 1024
# data_R = np.reshape(pictureR,(size_x-2,size_y-2))
# data_G = np.reshape(pictureG,(size_x-2,size_y-2))
# data_B = np.reshape(pictureB,(size_x-2,size_y-2))

arr = np.zeros((size_x-2,size_y-2,3))
arr[:,:,0] = np.reshape(pictureR,(size_x-2,size_y-2))
arr[:,:,1] = np.reshape(pictureG,(size_x-2,size_y-2))
arr[:,:,2] = np.reshape(pictureB,(size_x-2,size_y-2))



img = Image.fromarray(arr.astype('uint8'),mode="RGB")
img.show(title="calculated")

# y_data = YtoArr(y_data)
# y_data = YtoPic(y_data)
# y_data = np.reshape(y_data,(size_x-2,size_y-2))

# data_RGB = np.concatenate((y_data,data_R), axis=1)
# img = Image.fromarray(data_RGB)
# img.show(title="calculated")<jupyter_output>pic size: 576x1024 name: data/cat.jpg
pic size: 576x1024 name: data/cat.jpg
pic size: 576x1024 name: data/cat.jpg
{'fraction_non_alphanumeric': 0.17321841496741644, 'fraction_numerical': 0.026907714946394788, 'mean_word_length': 3.9102167182662537, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '542695', 'license': 'MIT', 'n_tokens_mistral': 2110, 'n_tokens_neox': 2028, 'n_words': 258, 'path': 'neuralNetwork.ipynb', 'repo_name': 'itamaralmog/Deep_Learning', 'size': '4757'}