Exemple #1
0
def init_model():
    model_path = 'models/Grasp_model'
    nsamples = 300

    max_batchsize = 128
    gpu_id = -1
    global nbatches, batchsize
    ## Set up model
    if nsamples > max_batchsize:
        batchsize = max_batchsize
        nbatches = int(nsamples / max_batchsize) + 1
    else:
        batchsize = nsamples
        nbatches = 1

    print('Loading grasp model')
    st_time = time.time()
    G = grasp_obj(model_path, gpu_id)
    G.BATCH_SIZE = batchsize
    G.test_init()

    return G
def predictGraspOnImage(I, objLoc):
    # default parameters
    model_path = '/home/team18/Grasp-Detector-master/models/Grasp_model'  # 'Grasp model you want to use'
    nsamples = 200  # 'Number of patch samples. More the better, but it\'ll get slower'
    nbest = 1  # 'Number of grasps to display'
    gscale = 0.234375  # 'Scale of grasp. Default is the one used in the paper, given a 720X1280 res image'
    imsize = max(I.shape[:2])
    gsize = int(gscale * imsize)  # Size of grasp patch
    # max_batchsize = 128
    gpu_id = 0  # 'GPU device id; -1 for cpu'

    # Set up model
    batchsize = nsamples
    nbatches = 1

    print(
        "\n-------------------------------------------------------------------"
    )
    print('Loading grasp model')
    st_time = time.time()
    G = grasp_obj(model_path, gpu_id)
    G.BATCH_SIZE = batchsize
    # G.test_close()  # 2/7/2018 added by BW
    G.test_init()
    P = Predictors(I, G)
    print('Time taken: {}s\n'.format(time.time() - st_time))

    fc8_predictions = []
    patch_Hs = []
    patch_Ws = []
    print('Predicting on samples')
    st_time = time.time()
    for _ in range(nbatches):
        P.graspNet_grasp(objLoc, patch_size=gsize, num_samples=batchsize)
        fc8_predictions.append(P.fc8_norm_vals)
        patch_Hs.append(P.patch_hs)
        patch_Ws.append(P.patch_ws)

    G.test_close()  # 12/19/2017 added by BW
    fc8_predictions = np.concatenate(fc8_predictions)
    patch_Hs = np.concatenate(patch_Hs)
    patch_Ws = np.concatenate(patch_Ws)

    r = np.sort(fc8_predictions, axis=None)
    r_no_keep = r[-nbest]
    print('Time taken: {}s'.format(time.time() - st_time))
    print(
        "-------------------------------------------------------------------\n"
    )
    for pindex in range(fc8_predictions.shape[0]):
        for tindex in range(fc8_predictions.shape[1]):
            if fc8_predictions[pindex, tindex] < r_no_keep:
                continue
            else:
                # tindex = 0
                I = drawRectangle(I, patch_Hs[pindex], patch_Ws[pindex],
                                  tindex, gsize)
                bestH = patch_Hs[pindex]
                bestW = patch_Ws[pindex]
                bestGraspAngle = tindex * (np.pi / 18.0) - np.pi / 2.0
                # bestGraspAngle = 0

    # print('displaying image')
    cv2.imshow('image', I)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    # TODO:
    bestGraspAngle = 0
    return bestH, bestW, bestGraspAngle
Exemple #3
0
imsize = max(I.shape[:2])
gsize = int(gscale * imsize)  # Size of grasp patch
max_batchsize = 128
gpu_id = args.gpu

# Set up model
if nsamples > max_batchsize:
    batchsize = max_batchsize
    nbatches = int(nsamples / max_batchsize) + 1
else:
    batchsize = nsamples
    nbatches = 1

print('Loading grasp model')
st_time = time.time()
G = grasp_obj(model_path, gpu_id)
G.BATCH_SIZE = batchsize
G.test_init()
P = Predictors(I, G)
print('Time taken: {}s'.format(time.time() - st_time))

fc8_predictions = []
patch_Hs = []
patch_Ws = []

print('Predicting on samples')
st_time = time.time()
for _ in range(nbatches):
    P.graspNet_grasp(patch_size=gsize, num_samples=batchsize)
    fc8_predictions.append(P.fc8_norm_vals)
    patch_Hs.append(P.patch_hs)