コード例 #1
0
    def save_file(self, name="mnist"):
        print("saving " + name)
        W = []
        b = []
        level = 0
        for layer in self.layers:
            level += 1
            if isinstance(layer, ParamMixin):
                W, b = layer.params()

                try:
                    if not self.android_load:
                        shapew1 = str(self.nn_dir + name + '_shape_w' +
                                      str(level) + '.txt')
                        np.savetxt(shapew1, W.shape)
                        shapeb1 = str(self.nn_dir + name + '_shape_b' +
                                      str(level) + '.txt')
                        np.savetxt(shapeb1, b.shape)
                        textw1 = str(self.nn_dir + name + '_w' + str(level) +
                                     '.txt')
                        Wout, xshape = store.store_w(W)
                        np.savetxt(textw1, Wout)
                        textb1 = str(self.nn_dir + name + '_b' + str(level) +
                                     '.txt')
                        bout, xshape = store.store_b(b)
                        np.savetxt(textb1, bout)
                        print(str(level) + " save.")
                except:
                    pass
コード例 #2
0
ファイル: neuralnetwork.py プロジェクト: radiodee1/nnet
    def save_file(self, name="mnist"):
        print ("saving " + name)
        W = []
        b = []
        level = 0
        for layer in self.layers:
            level += 1
            if isinstance(layer, ParamMixin):
                W, b = layer.params()

                if not self.android_load:
                    shapew1 = str(self.nn_dir + name + "_shape_w" + str(level) + ".txt")
                    np.savetxt(shapew1, W.shape)
                    shapeb1 = str(self.nn_dir + name + "_shape_b" + str(level) + ".txt")
                    np.savetxt(shapeb1, b.shape)
                    textw1 = str(self.nn_dir + name + "_w" + str(level) + ".txt")
                    Wout, xshape = store.store_w(W)
                    np.savetxt(textw1, Wout)
                    textb1 = str(self.nn_dir + name + "_b" + str(level) + ".txt")
                    bout, xshape = store.store_b(b)
                    np.savetxt(textb1, bout)
                    print (str(level) + " save.")
                if False:
                    # pickle W and b
                    f1 = file(str(self.nn_dir + name + "-weights" + str(level) + ".save"), "wb")
                    cPickle.dump(W, f1, protocol=cPickle.HIGHEST_PROTOCOL)
                    f1.close()
                    f2 = file(str(self.nn_dir + name + "-bias" + str(level) + ".save"), "wb")
                    cPickle.dump(b, f2, protocol=cPickle.HIGHEST_PROTOCOL)
                    f2.close()
コード例 #3
0
 def save_file(self, name = "mnist"):
     print ("saving " + name)
     W = []
     b = []
     level = 0
     for layer in self.layers:
         level += 1
         if isinstance(layer, ParamMixin):
             W, b = layer.params()
             
             try:
                 if not self.android_load :
                     shapew1 = str(self.nn_dir+name+'_shape_w'+str(level)+'.txt')
                     np.savetxt(shapew1, W.shape)
                     shapeb1 = str(self.nn_dir+name+'_shape_b'+str(level)+'.txt')
                     np.savetxt(shapeb1, b.shape)
                     textw1 = str(self.nn_dir+name+'_w'+str(level)+'.txt')
                     Wout, xshape = store.store_w(W)
                     np.savetxt(textw1, Wout)
                     textb1 = str(self.nn_dir+name+'_b'+str(level)+'.txt')
                     bout , xshape = store.store_b(b)
                     np.savetxt(textb1, bout)
                     print (str (level) + " save.")
             except:
                 pass