Exemple #1
0
def test_Pooling():
    np.random.seed(1)
    A_prev = np.random.randn(1, 5, 5, 3)
    hparameters = {"stride": 1, "f": 2}
    max_output = pool_forward(A_prev, hparameters)
    np.testing.assert_array_equal(Pooling(A_prev[0, :, :, :], hparameters),
                                  max_output[0, :, :, :])
 def layerResult(self, layer, X, pos):
     """ 
         layer-dictonary l_type,kernel,hparams
         X-numpy array(n_H_prev, n_W_prev, n_C_prev)
         pooling-
             X-numpy array(n_H_prev, n_W_prev, n_C_prev)
             hparameters-"f" and "stride"
             Pooling(X,hparameters,mode="max")
         conv
             vecConv(X,kernel,hparameters):
             X- numpy arrya shape (n_H_prev, n_W_prev, n_C_prev)
             kernel-numpy array of shape (f, f, n_C_prev, n_C)
             hparameters-- python dictinory containing stride and pad
     """
     if (layer["l_type"] == "conv"):
         w = kernels[layer["kernel"]]
         hparam = layer["hparams"]
         return vecConv(X, w[:, :, :, pos[0]:pos[1]], hparam)
     else:
         hparam = layer["hparams"]
         mode = layer["l_type"]
         #batch size of 1
         return Pooling(X[:, :, pos[0]:pos[1]], hparam, mode)
        data_variable={"data":X,"pos":a,"layer":layer}
        a=(start,end)
        layer={"l_type":"conv","kernel":"W1","hparams":{"stride":1,"pad":0}}
        pooling layer testing
        layer2={"l_type":"max","hparams":{"stride":1,"f":2}}
    """
    c, addr = s.accept()
    #receive data from client
    tic = time.process_time()
    data_variable = receive_array(data, payload_size, c)
    print('Connect with', addr, data_variable["data"].shape)
    #imgout=y.conv_forward(data_variable["data"], w.W1[:,:,:,data_variable["pos"]:], w.b1[:,:,:,data_variable["pos"]:],data_variable["hpara"])
    #out={"data":imgout}
    X = data_variable["data"]
    hparam = data_variable["layer"]["hparams"]
    mode = data_variable["layer"]["l_type"]
    if (mode == "conv"):
        pos = data_variable["pos"]
        w = kernels[data_variable["layer"]["kernel"]]
        out = vecConv(X, w[:, :, :, pos[0]:pos[1]], hparam)
    else:
        out = Pooling(X, hparam, mode)
    dout = {"data": out}
    send(c, dout)
    toc = time.process_time()
    print("Computation time for conv part2 = " + str(1000 * (toc - tic)) +
          "ms")
    #send data to client
    #c.send(bytes("Welcome to server",'utf-8'))
    c.close()
Exemple #4
0
while True:
    """
        data_variable={"data":X,"pos":a,"layer":layer}
        a=(start,end)
        layer={"l_type":"conv","kernel":"W1","hparams":{"stride":1,"pad":0}}
        pooling layer testing
        layer2={"l_type":"max","hparams":{"stride":1,"f":2}}
    """
    c, addr = s.accept()
    #receive data from client
    tic = time.process_time()
    data_variable = receive_array(data, payload_size, c)
    print('Connect with', addr, data_variable["data"].shape)
    #imgout=y.conv_forward(data_variable["data"], w.W1[:,:,:,data_variable["pos"]:], w.b1[:,:,:,data_variable["pos"]:],data_variable["hpara"])
    #out={"data":imgout}
    pos = data_variable["pos"]
    hparam = data_variable["layer"]["hparams"]
    mode = data_variable["layer"]["l_type"]
    if (mode == "conv"):
        out = vecConv(X, w[:, :, :, pos[0]:pos[1]], hparam)
    else:
        out = Pooling(X[:, :, pos[0]:pos[1]], hparam, mode)
    send(c, out)
    toc = time.process_time()
    print("Computation time for conv part2 = " + str(1000 * (toc - tic)) +
          "ms")
    #send data to client
    #c.send(bytes("Welcome to server",'utf-8'))
    c.close()