MCPcopy
hub / github.com/tensorlayer/TensorLayer / find_top_dataset

Method find_top_dataset

tensorlayer/db.py:302–359  ·  view source on GitHub ↗

Finds and returns a dataset from the database which matches the requirement. Parameters ---------- dataset_name : str The name of dataset. sort : List of tuple PyMongo sort comment, search "PyMongo find one sorting" and `collection level opera

(self, dataset_name=None, sort=None, **kwargs)

Source from the content-addressed store, hash-verified

300 return False
301
302 def find_top_dataset(self, dataset_name=None, sort=None, **kwargs):
303 """Finds and returns a dataset from the database which matches the requirement.
304
305 Parameters
306 ----------
307 dataset_name : str
308 The name of dataset.
309 sort : List of tuple
310 PyMongo sort comment, search "PyMongo find one sorting" and `collection level operations <http://api.mongodb.com/python/current/api/pymongo/collection.html>`__ for more details.
311 kwargs : other events
312 Other events, such as description, author and etc (optinal).
313
314 Examples
315 ---------
316 Save dataset
317 >>> db.save_dataset([X_train, y_train, X_test, y_test], 'mnist', description='this is a tutorial')
318
319 Get dataset
320 >>> dataset = db.find_top_dataset('mnist')
321 >>> datasets = db.find_datasets('mnist')
322
323 Returns
324 --------
325 dataset : the dataset or False
326 Return False if nothing found.
327
328 """
329
330 self._fill_project_info(kwargs)
331 if dataset_name is None:
332 raise Exception("dataset_name is None, please give a dataset name")
333 kwargs.update({'dataset_name': dataset_name})
334
335 s = time.time()
336
337 d = self.db.Dataset.find_one(filter=kwargs, sort=sort)
338
339 if d is not None:
340 dataset_id = d['dataset_id']
341 else:
342 print("[Database] FAIL! Cannot find dataset: {}".format(kwargs))
343 return False
344 try:
345 dataset = self._deserialization(self.dataset_fs.get(dataset_id).read())
346 pc = self.db.Dataset.find(kwargs)
347 print("[Database] Find one dataset SUCCESS, {} took: {}s".format(kwargs, round(time.time() - s, 2)))
348
349 # check whether more datasets match the requirement
350 dataset_id_list = pc.distinct('dataset_id')
351 n_dataset = len(dataset_id_list)
352 if n_dataset != 1:
353 print(" Note that there are {} datasets match the requirement".format(n_dataset))
354 return dataset
355 except Exception as e:
356 exc_type, exc_obj, exc_tb = sys.exc_info()
357 fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
358 logging.info("{} {} {} {} {}".format(exc_type, exc_obj, fname, exc_tb.tb_lineno, e))
359 return False

Callers 1

task_script.pyFile · 0.80

Calls 4

_fill_project_infoMethod · 0.95
_deserializationMethod · 0.95
getMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected