We are using capnproto to serialize the HTMPrediction model with the method below:
def writeToCheckpoint(self, checkpointDir):
"""Serializes model using capnproto and writes data to ``checkpointDir``"""
proto = self.getSchema().new_message()
self.write(proto)
checkpointPath = self._getModelCheckpointFilePath(checkpointDir)
# Clean up old saved state, if any
if os.path.exists(checkpointDir):
if not os.path.isdir(checkpointDir):
raise Exception(("Existing filesystem entry <%s> is not a model"
" checkpoint -- refusing to delete (not a directory)") \
% checkpointDir)
if not os.path.isfile(checkpointPath):
raise Exception(("Existing filesystem entry <%s> is not a model"
" checkpoint -- refusing to delete"\
" (%s missing or not a file)") % \
(checkpointDir, checkpointPath))
shutil.rmtree(checkpointDir)
# Create a new directory for saving state
self.__makeDirectoryFromAbsolutePath(checkpointDir)
with open(checkpointPath, 'wb') as f:
proto.write(f)
When we look at the size of the serialized files, the total is over 9 MB, if we use to_bytes()
instead of to_bytes_packed()
the size is 27 MB.
Can anyone explain why the size of the serialized buffer is so large? I just want to point this out in case something is wrong? Can anyone confirm this is working as it’s supposed to?