コード例 #1
0
    def getPredictionRelative(self):
        model = load_model("/Users/sean/Documents/Projects/Packing-Algorithm/model/lstm_num_5_layer_128_56_2_epochs_70.h5")
        pre_train = pd.read_csv("/Users/sean/Documents/Projects/Data/pre_train.csv") # 读取形状
        _input = pd.read_csv("/Users/sean/Documents/Projects/Data/input_seq.csv") # 读取输入
        _output = pd.read_csv("/Users/sean/Documents/Projects/Data/output_relative_position.csv") # 读取输入
        
        
        # index=random.randint(4000,5000)
        index=4500

        polys=json.loads(pre_train["polys"][index]) # 形状
        X = np.array([json.loads(_input["x_256"][index])]) # 输入
        predicted_Y = model.predict(X, verbose=0)[0]*1500
        print(predicted_Y)
        Y=np.array(json.loads(_output["y"][index]))*1500
        print(Y)

        old_centroid=[0,0]
        for i,poly in enumerate(polys):
            # 获得初始的中心和预测的位置
            centroid_origin=GeoFunc.getPt(Polygon(poly).centroid)
            centroid_predicted=[Y[i][0]+old_centroid[0],Y[i][1]+old_centroid[1]] 

            # 获得新的形状并更新
            new_poly=GeoFunc.getSlide(poly,centroid_predicted[0]-centroid_origin[0],centroid_predicted[1]-centroid_origin[1])
            old_centroid=GeoFunc.getPt(Polygon(new_poly).centroid)

            PltFunc.addPolygon(poly)
            PltFunc.addPolygonColor(new_poly)

        PltFunc.showPlt()
コード例 #2
0
ファイル: packing.py プロジェクト: seanys/Learn-to-Pack
    def __init__(self, polys, **kw):
        self.polys = PolyListProcessor.deleteRedundancy(copy.deepcopy(polys))
        self.area_list, self.first_vec_list, self.centroid_list = [], [], [
        ]  # 作为参考
        for poly in self.polys:
            P = Polygon(poly)
            self.centroid_list.append(GeoFunc.getPt(P.centroid))
            self.area_list.append(int(P.area))
            self.first_vec_list.append(
                [poly[1][0] - poly[0][0], poly[1][1] - poly[0][1]])
        self.nfp_list = [[0] * len(self.polys) for i in range(len(self.polys))]
        self.load_history = False
        self.history_path = None
        self.history = None
        if 'history_path' in kw:
            self.history_path = kw['history_path']

        if 'load_history' in kw:
            if kw['load_history'] == True:
                # 从内存中加载history 直接传递pandas的df对象 缩短I/O时间
                if 'history' in kw:
                    self.history = kw['history']
                self.load_history = True
                self.loadHistory()

        self.store_nfp = False
        if 'store_nfp' in kw:
            if kw['store_nfp'] == True:
                self.store_nfp = True

        self.store_path = None
        if 'store_path' in kw:
            self.store_path = kw['store_path']

        if 'get_all_nfp' in kw:
            if kw['get_all_nfp'] == True and self.load_history == False:
                self.getAllNFP()

        if 'fast' in kw:  # 为BLF进行多进程优化
            if kw['fast'] == True:
                self.res = [[0] * len(self.polys)
                            for i in range(len(self.polys))]
                #pool=Pool()
                for i in range(1, len(self.polys)):
                    for j in range(0, i):
                        # 计算nfp(j,i)
                        #self.res[j][i]=pool.apply_async(getNFP,args=(self.polys[j],self.polys[i]))
                        self.nfp_list[j][i] = GeoFunc.getSlide(
                            getNFP(self.polys[j],
                                   self.polys[i]), -self.centroid_list[j][0],
                            -self.centroid_list[j][1])
コード例 #3
0
ファイル: packing.py プロジェクト: seanys/Learn-to-Pack
 def getDirectNFP(self, poly1, poly2, **kw):
     if 'index' in kw:
         i = kw['index'][0]
         j = kw['index'][1]
         centroid = GeoFunc.getPt(Polygon(self.polys[i]).centroid)
     else:
         # 首先获得poly1和poly2的ID
         i = self.getPolyIndex(poly1)
         j = self.getPolyIndex(poly2)
         centroid = GeoFunc.getPt(Polygon(poly1).centroid)
     # 判断是否计算过并计算nfp
     if self.nfp_list[i][j] == 0:
         nfp = NFP(poly1, poly2).nfp
         #self.nfp_list[i][j]=GeoFunc.getSlide(nfp,-centroid[0],-centroid[1])
         if self.store_nfp == True:
             with open(
                     "/Users/sean/Documents/Projects/Packing-Algorithm/record/nfp.csv",
                     "a+") as csvfile:
                 writer = csv.writer(csvfile)
                 writer.writerows([[poly1, poly2, nfp]])
         return nfp
     else:
         return GeoFunc.getSlide(self.nfp_list[i][j], centroid[0],
                                 centroid[1])
コード例 #4
0
    def getPredictionAbsolute(self):
        model = load_model("/Users/sean/Documents/Projects/Packing-Algorithm/model/absolute_lstm_num_8_layer_128_56_2_epochs_200.h5")
        
        file= pd.read_csv("/Users/sean/Documents/Projects/Data/8_lstm_test.csv") # 读取输入
        
        index=random.randint(3700,4700)
        index=3000

        polys=json.loads(file["polys"][index]) # 形状
        X = np.array([json.loads(file["x_256"][index])]) # 输入
        predicted_Y = model.predict(X, verbose=0)[0]*4000

        for i,poly in enumerate(polys):
            centroid_origin=GeoFunc.getPt(Polygon(poly).centroid)
            PltFunc.addPolygon(poly)

            new_poly=GeoFunc.getSlide(poly,predicted_Y[i][0]-centroid_origin[0],predicted_Y[i][1]-centroid_origin[1])
            PltFunc.addPolygonColor(new_poly)

        PltFunc.showPlt()