Best Python code snippet using autotest_python
simulatorTestDemo.py
Source:simulatorTestDemo.py
1import os2import numpy as np3import torch4import argparse5from simulateTest.AutoGraspShapeCoreUtil import AutoGraspUtil6# parser = argparse.ArgumentParser(description='ShapeNetSem Grasp testing')7# parser.add_argument('-t', '--testFile', default='prediction/500ntop10.txt', type=str, metavar='FILE', help='testFile path')8# # parser.add_argument('-n', '--samplePerObject', default=10, type=int, metavar='N', help='sample num per object')9# parser.add_argument('-p', '--processNum', default=18, type=int, metavar='N', help='process num using')10# parser.add_argument('-w', '--haveWidth', default=1, type=int, metavar='N', help='0 : no width ; 1 : have width')11# parser.add_argument('--gripperFile', default='/data/shapeNet/annotator2/parallel_simple.urdf', type=str, metavar='FILE', help='gripper file')12# parser.add_argument('--objMeshRoot', default='/data/shapeNet/urdf', type=str, metavar='PATH', help='obj mesh path')13parser = argparse.ArgumentParser(description='ShapeNetSem Grasp testing')14parser.add_argument('-t', '--testFile', default='gpnet_data/prediction/nms_poses_view0.txt', type=str, metavar='FILE', help='testFile path')15# parser.add_argument('-n', '--samplePerObject', default=10, type=int, metavar='N', help='sample num per object')16parser.add_argument('-p', '--processNum', default=10, type=int, metavar='N', help='process num using')17# parser.add_argument('-w', '--haveWidth', default=0, type=int, metavar='N', help='0 : no width ; 1 : have width')18parser.add_argument('-w', "--width", action="store_true", dest="width", default=False, help="turn on this param if test file contains width.")19parser.add_argument('--gripperFile', default='gpnet_data/gripper/parallel_simple.urdf', type=str, metavar='FILE', help='gripper file')20parser.add_argument('--objMeshRoot', default='gpnet_data/urdf', type=str, metavar='PATH', help='obj mesh path')21def getObjStatusAndAnnotation(testFile, haveWidth=False):22 with open(testFile, 'r') as testData:23 lines = testData.readlines()24 objIdList = []25 quaternionDict = {}26 centerDict = {}27 # 0: scaling 1~3: position 4~7: orientation 8: staticFrictionCoeff28 objId = 'invalid'29 objCounter = -130 annotationCounter = -131 for line in lines:32 # new object33 msg = line.strip()34 if len(msg.split(',')) < 2 :35 objId = msg.strip()36 # skip invalid37 # begin38 objCounter += 139 objIdList.append(objId)40 quaternionDict[objId] = np.empty(shape=(0, 4), dtype=np.float)41 centerDict[objId] = np.empty(shape=(0, 3), dtype=np.float)42 annotationCounter = -143 # read annotation44 else:45 # skip invalid object46 if objId == 'invalid':47 continue48 # begin49 annotationCounter += 150 pose = msg.split(',')51 # print(objId, annotationCounter)52 if haveWidth:53 length = float(pose[0]) * 0.085 # arbitrary value, will not be used in AutoGrasp54 length = length if length < 0.085 else 0.08555 position = np.array([float(pose[1]), float(pose[2]), float(pose[3])])56 quaternion = np.array([float(pose[4]), float(pose[5]), float(pose[6]), float(pose[7])])57 # quaternion = quaternion[[1, 2, 3, 0]]58 else:59 length = 0.000 # arbitrary value, will not be used in AutoGrasp60 position = np.array([float(pose[0]), float(pose[1]), float(pose[2])])61 quaternion = np.array([float(pose[3]), float(pose[4]), float(pose[5]), float(pose[6])])62 # quaternion = quaternion[[1, 2, 3, 0]]63 # print(objCounter, annotationCounter)64 quaternionDict[objId] = np.concatenate((quaternionDict[objId], quaternion[None, :]), axis=0)65 centerDict[objId] = np.concatenate((centerDict[objId], position[None, :]), axis=0)66 return quaternionDict, centerDict, objIdList67if __name__ == "__main__":68 cfg = parser.parse_args()69 objMeshRoot = cfg.objMeshRoot70 processNum = cfg.processNum71 gripperFile = cfg.gripperFile72 haveWidth = cfg.width73 testInfoFile = cfg.testFile74 logFile = cfg.testFile[:-4] + '_log.csv'75 open(logFile, 'w').close()76 simulator = AutoGraspUtil()77 quaternionDict, centerDict, objIdList = getObjStatusAndAnnotation(testInfoFile, haveWidth)78 for objId in objIdList:79 q = quaternionDict[objId]80 c = centerDict[objId]81 simulator.addObject2(82 objId=objId,83 quaternion=q,84 translation=c85 )86 simulator.parallelSimulation(87 logFile=logFile,88 objMeshRoot=objMeshRoot,89 processNum=processNum,90 gripperFile=gripperFile,91 )92 annotationSuccessDict = simulator.getSuccessData(logFile=logFile)93 # print(top 10% 30% 50% 100%)94 top10, top30, top50, top100 = simulator.getStatistic(annotationSuccessDict)...
ga.py
Source:ga.py
...31toolbox.register("mutate", mutGaussianInt, mu=mu, sigma=sigma, indpb=0.25)32toolbox.register("select", tools.selBest)33if __name__ == "__main__":34 start_time = time.time()35 pop, log, hof, history = parallel_simple(toolbox, pop_sz, cxpb, mutpb, ngen, n_jobs=4)36 print("total runtime:", time.time() - start_time)37 print("Best individual is: %s\nwith fitness: %s" % (hof[0], hof[0].fitness.values[0]))38 print("Final population:\n", pop)39 print("Log:\n", log)40 output = []41 for i in hof:42 output.append(i + [i.fitness.values[0]])43 print(i + [i.fitness.values[0]])44 output = np.array(output)45 np.savetxt('ga_results_backup2.csv', output, fmt='%10.5f', delimiter=',')46 gene_order = []47 for i in history.genealogy_history:48 gene_order.append(history.genealogy_history[i])49 gene_order = np.array(gene_order)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!