<jupyter_start><jupyter_text>CH1 some explanations<jupyter_code>import numpy as np
import matplotlib.pylab as plt
from matplotlib import gridspec
from ccgpack.shapes import *
import tensorflow as tf

%matplotlib inline
fig, (ax1,ax2)= plt.subplots(ncols=2, nrows=1, figsize=(20, 10))

num = 200
imgx = np.zeros((num, num, 3), dtype=np.double)
imgy = np.zeros((num, num, 3), dtype=np.double)

num = 10
begins = random_inside(imgx,num=num)
ends = random_inside(imgx,num=num)

rs = np.random.randint(10,50,2)
centers = random_inside(imgx,num=2)

imgx = draw_line(imgx,begins=begins,ends=ends,value=(1,0,0))
imgx = draw_circle(imgx,centers=centers,rs=rs,rmin=10,rmax=20,fill=True,value=(0,1,1))

imgy = draw_circle(imgy,centers=centers,rs=rs,rmin=10,rmax=20,value=(1,1,0))
# imgy = draw_square(imgy,centers=centers,lxs=rs,lys=rs,fill=True,value=(0,0,1))
imgy = draw_equitri(imgy,centers,rs,fill=1,value=(0,0,1))


ax1.imshow(imgx)
ax1.axis('off')
ax2.imshow(imgy)
ax2.axis('off')
def data_provider(n):
    
    x = []
    y = []
    for i in range(n):
    
        imgx = np.zeros((num, num, 3), dtype=np.double)
        imgy = np.zeros((num, num, 3), dtype=np.double)

#         # draw line
#         for _ in range(50):
#             lc = np.random.randint(10,num-10,4)
#             rr, cc = line(lc[0], lc[1], lc[2], lc[3])
#             imgx[rr, cc, 0] = 10

        for _ in range(3):
            # fill circle
            circ = np.random.randint(50,num-50,2)
            rmax = np.min([np.min(circ), np.min(num-circ)])
            rad = np.random.randint(10,rmax)
            rr, cc = circle(circ[0], circ[1], rad, imgx.shape)
            imgy[rr, cc, :] = (10, 10, 0)

            for rp in range(rad-5,rad):
                rr, cc = circle_perimeter(circ[0], circ[1], rp)
                imgx[rr, cc, :] = (50, 0, 50)
        
        x.append(imgx)
        y.append(imgy)
        
    return np.array(x),np.array(y)
x,y = data_provider(15)
print (x.shape)

fig, (ax1,ax2)= plt.subplots(ncols=2, nrows=1, figsize=(20, 10))
ax1.imshow(x[0])
ax2.imshow(y[0])
nx,ny,n_channel = num,num,3

x_in = tf.placeholder(tf.float32,[None,nx,ny,n_channel])
y_true = tf.placeholder(tf.float32,[None,nx,ny,n_channel])
learning_rate = tf.placeholder(tf.float32)
# drop_out = tf.placeholder(tf.float32)

x1 = tf.layers.conv2d(x_in,filters=8,kernel_size=5,strides=(1, 1),padding='same',
        activation=tf.nn.relu)
x = tf.layers.conv2d(x1,filters=8,kernel_size=5,strides=(1, 1),padding='same',
        activation=tf.nn.relu)
x = tf.layers.conv2d(x,filters=8,kernel_size=5,strides=(1, 1),padding='same',
        activation=tf.nn.relu)
x = tf.layers.conv2d(x,filters=8,kernel_size=5,strides=(1, 1),padding='same',
        activation=tf.nn.relu)
x = x+x1
x = tf.layers.conv2d(x,filters=8,kernel_size=5,strides=(1, 1),padding='same',
        activation=tf.nn.relu)
x = tf.layers.conv2d(x,filters=8,kernel_size=5,strides=(1, 1),padding='same',
        activation=tf.nn.relu)

# x = tf.layers.dropout(x, drop_out)
x_out = tf.layers.conv2d(x,filters=n_channel,kernel_size=5,strides=(1, 1),padding='same',
        activation=tf.nn.relu)

cost = tf.reduce_mean(tf.pow(y_true - x_out, 2))
optimizer = tf.train.AdamOptimizer(learning_rate).minimize(cost)

sess = tf.InteractiveSession()
init = tf.global_variables_initializer()
sess.run(init)
for i in range(500):
    x,y = data_provider(5)
    _, c = sess.run([optimizer, cost], feed_dict=
                     {x_in: x, y_true: y, learning_rate: 0.01})
    if i%10==0:
        print c
fig,(ax1,ax2,ax3) = plt.subplots(ncols=3,nrows=1,figsize=(15,7))

x,y = data_provider(1)

x_pred = sess.run(x_out, feed_dict={x_in:x})
    
ax1.imshow(x[0])
ax1.set_title('Input')
ax2.imshow(y[0])
ax2.set_title('Output')
ax3.imshow(x_pred[0])
ax3.set_title('Prediction')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17976939203354297, 'fraction_numerical': 0.046645702306079666, 'mean_word_length': 3.8998716302952503, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '570685', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1618, 'n_words': 240, 'path': 'notebooks/shapes.ipynb', 'repo_name': 'vafaei-ar/ccgpack', 'size': '3816'}