|
9 | 9 | import os |
10 | 10 | import seaborn as sns |
11 | 11 | import dill |
| 12 | +import traceback |
| 13 | +from tensorflow import keras |
12 | 14 |
|
13 | 15 |
|
14 | 16 | class Database: |
@@ -241,20 +243,29 @@ def __init__(self, database_connector: Database): |
241 | 243 | self.__database_connector = database_connector |
242 | 244 | self.__thread_pool = ThreadPoolExecutor() |
243 | 245 |
|
| 246 | + def read(self, filename: str, service_type: str) -> object: |
| 247 | + binary_path = TransformStorage.get_read_binary_path( |
| 248 | + filename, service_type) |
| 249 | + try: |
| 250 | + binary_instance = open( |
| 251 | + binary_path, |
| 252 | + self.__READ_OBJECT_OPTION) |
| 253 | + return dill.load(binary_instance) |
| 254 | + except Exception: |
| 255 | + traceback.print_exc() |
| 256 | + return keras.models.load_model(binary_path) |
| 257 | + |
244 | 258 | def save(self, instance: object, filename: str) -> None: |
245 | 259 | output_path = TransformStorage.get_write_binary_path(filename) |
246 | 260 |
|
247 | | - instance_output = open(output_path, |
248 | | - self.__WRITE_OBJECT_OPTION) |
249 | | - dill.dump(instance, instance_output) |
250 | | - instance_output.close() |
251 | | - |
252 | | - def read(self, filename: str, service_type: str) -> object: |
253 | | - binary_instance = open( |
254 | | - TransformStorage.get_read_binary_path( |
255 | | - filename, service_type), |
256 | | - self.__READ_OBJECT_OPTION) |
257 | | - return dill.load(binary_instance) |
| 261 | + try: |
| 262 | + keras.models.save_model(instance, output_path) |
| 263 | + except Exception: |
| 264 | + traceback.print_exc() |
| 265 | + instance_output = open(output_path, |
| 266 | + self.__WRITE_OBJECT_OPTION) |
| 267 | + dill.dump(instance, instance_output) |
| 268 | + instance_output.close() |
258 | 269 |
|
259 | 270 | def delete(self, filename: str) -> None: |
260 | 271 | self.__thread_pool.submit( |
|
0 commit comments