def getModel(uid): if uid in modelCache: return modelCache[uid] modelDir = _getModelDir(uid) if not os.path.exists(modelDir): os.makedirs(modelDir) model = Model(checkpointDir=modelDir) if model.hasCheckpoint(): model.load() modelCache[uid] = model return model
def test_checkpoint(self): model1 = Model(checkpointDir=MODEL_CHECKPOINT_DIR) term = Term().createFromString("fox") for _ in range(5): prediction = model1.feedTerm(term) self.assertTrue(len(prediction.bitmap)) model1.save() model2 = Model(checkpointDir=MODEL_CHECKPOINT_DIR) model2.load() prediction = model2.feedTerm(term) self.assertTrue(len(prediction.bitmap))
def testLoadWithoutCheckpointFile(self): model = Model(checkpointDir=MODEL_CHECKPOINT_DIR) with self.assertRaises(Exception) as e: model.load() self.assertIn("Could not find checkpoint file", e.exception)
def testLoadWithoutCheckpointDirectory(self): model = Model() with self.assertRaises(Exception) as e: model.load() self.assertIn("No checkpoint directory specified", e.exception)