<jupyter_start><jupyter_text>Server<jupyter_code>s = time.time()
w0, b0 = model_new.layers[0].get_weights()
model_ = Sequential()
for layer in model_new.layers[1:]:
  model_.add(layer)
model_.build(input_shape = model_new.layers[0].output_shape)
listw = []
for d in np.arange(w0.shape[-1]):
  w_reshape = w0[:,:,:,d].reshape(1,-1)
  w_plus = [np.random.rand() for i in range(w_reshape.shape[-1])]
  listw.append([w_reshape[0],w_plus])
w = np.array(listw)
k = np.array([[np.random.rand(),np.random.rand()],
              [np.random.rand(),np.random.rand()]])
kd = np.linalg.inv(k)
listKW = []
for i in np.arange(w.shape[0]):
    listKW.append(k.dot(w[i]))
kw = np.array(listKW)
print('\nTime: ',time.time() - s)
kw.shape<jupyter_output><empty_output><jupyter_text>Client<jupyter_code>s = time.time()
strd, kernel = 1, 3
listXX = []
for _x in np.arange(x_.shape[0]):
  listX = []
  for h in np.arange(0,x_.shape[1],strd):
    list_width = []
    for width in np.arange(0,x_.shape[2],strd):
      width_reshape = x_[_x,h:h+kernel,width:width+kernel,:].reshape(1,-1)
      x_plus = [np.random.rand() for i in range(width_reshape.shape[-1])]
      list_width.append([width_reshape[0], x_plus])
      if width+kernel == x_.shape[2]:
        break
    listX.append(list_width)
    if h+kernel == x_.shape[1]:
      break
  listXX.append(listX)
ex = np.array(listXX)
listKWXX = []
for xx in np.arange(ex.shape[0]):
  listKWX = []
  for h in np.arange(ex.shape[1]):
    listwi = []
    for wi in np.arange(ex.shape[2]):
      lw = []
      for ww_ in np.arange(kw.shape[0]):
        lw.append(kw[ww_].dot(ex[xx,h,wi].T))
      listwi.append(lw)
    listKWX.append(listwi)
  listKWXX.append(listKWX)
print('\nTime: ',time.time() - s)
kwx = np.array(listKWXX)
kwx.shape<jupyter_output>Time:  0.09017586708068848<jupyter_text>Server<jupyter_code>def Relu(x):
  return np.maximum(x,0)
s = time.time()
oy = np.zeros(kwx.shape[0:4])
for xx in np.arange(oy.shape[0]):
  for height in np.arange(oy.shape[1]):
    for width in np.arange(oy.shape[2]):
      for dept in np.arange(oy.shape[3]):
        oy[xx,height,width,dept] = Relu(kd.dot(kwx[xx,height,width,dept])[0][0]+b0[dept])
print('Model dự đoán: ',model_.predict(oy).argmax())

print('\nTime: ',time.time() - s)
s = time.time()
print('Model dự đoán: ',model_.predict(oy).argmax())
print('\nTime: ',time.time() - s)<jupyter_output><empty_output>