示例#1
0
def test_conv():
    np.random.seed(1)
    A_prev = np.random.randn(1, 3, 3, 3)
    hparameters = {"pad": 0, "stride": 1}
    w = np.ones((2, 2, 3, 1))
    b = np.zeros(((1, 1, 1, 1)))
    c_out = conv_forward(A_prev, w, b, hparameters)
    print(c_out.shape)
    print(c_out[0, :, :, :])
    v_out = vecConv(A_prev[0, :, :, :], w, hparameters)
    print(v_out.shape)
    print(v_out)
    np.testing.assert_array_equal(v_out, c_out[0, :, :, :])
示例#2
0
    while len(data) < msg_size:
        data += conn.recv(4096)

    frame_data = data[:msg_size]
    data = data[msg_size:]

    # Extract frame
    frame = pickle.loads(frame_data)
    return frame


while True:
    c, addr = s.accept(
    )  # retunrs the socket connection object and address of client
    # 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}
    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()
示例#3
0
# c.connect(('localhost',9999)) #ip address and port
# send data to server
# send(c,conv_dict)
# receive data from server
# out=receive_array(data,payload_size,c)
# print(out["data"].shape)
np.random.seed(1)  # always use the same initialized random numbers
# h256X256 image# here is the image input to detect
image = np.random.randn(1, 256, 256, 3)
# divide the weights shape to 2 so can take size to divide
a = round(w.W1.shape[3] / 2)
conv_dict = {"data": image, "hpara": w.hparameters1, "pos": a}
#tic = time.process_time()
c = client(conv_dict)
c.start()
# client process conv portion
tic = time.process_time()
out = y.conv_forward(image, w.W1[:, :, :, :a], w.b1[:, :, :, :a],
                     w.hparameters1)
toc = time.process_time()
print("Computation time conv part1 = " + str(1000 * (toc - tic)) + "ms")
tic = time.process_time()
c.join()
print(c.value()["data"].shape)
toc = time.process_time()
out1 = np.concatenate((out, c.value()["data"]), axis=3)
#toc = time.process_time()
print("Computation time for join = " + str(1000 * (toc - tic)) + "ms")
print("Out1 shape", out1.shape)
示例#4
0
#YOLO conv net
import time
from yolo import conv_forward, pool_forward
from weights import image, W1, b1, W2, b2, W3, b3, hparameters1, hparameters2, hparameters3, hparameters4, hparameters5
tic = time.process_time()
out1 = conv_forward(image, W1, b1,
                    hparameters1)  #3x3 s-1 pad-1 filters 16 activation-leaky
out2 = pool_forward(out1, hparameters2, mode="max")  #2x2 s-2
out3 = conv_forward(out2, W2, b2,
                    hparameters3)  #3x3 s-1 pad-1 filters 32 activation-leaky
out4 = pool_forward(out3, hparameters4, mode="max")  #2x2 s-2
out5 = conv_forward(out4, W3, b3,
                    hparameters5)  #3x3 s-1 pad-1 filters 32 activation-leaky
toc = time.process_time()
print("Computation time = " + str(1000 * (toc - tic)) + "ms")
out5.shape