本文整理汇总了Python中cache.cache方法的典型用法代码示例。如果您正苦于以下问题:Python cache.cache方法的具体用法?Python cache.cache怎么用?Python cache.cache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cache
的用法示例。
在下文中一共展示了cache.cache方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: transfer_values
# 需要导入模块: import cache [as 别名]
# 或者: from cache import cache [as 别名]
def transfer_values(self, image_path=None, image=None):
"""
Calculate the transfer-values for the given image.
These are the values of the last layer of the Inception model before
the softmax-layer, when inputting the image to the Inception model.
The transfer-values allow us to use the Inception model in so-called
Transfer Learning for other data-sets and different classifications.
It may take several hours or more to calculate the transfer-values
for all images in a data-set. It is therefore useful to cache the
results using the function transfer_values_cache() below.
:param image_path:
The input image is a jpeg-file with this file-path.
:param image:
The input image is a 3-dim array which is already decoded.
The pixels MUST be values between 0 and 255 (float or int).
:return:
The transfer-values for those images.
"""
# Create a feed-dict for the TensorFlow graph with the input image.
feed_dict = self._create_feed_dict(image_path=image_path, image=image)
# Use TensorFlow to run the graph for the Inception model.
# This calculates the values for the last layer of the Inception model
# prior to the softmax-classification, which we call transfer-values.
transfer_values = self.session.run(self.transfer_layer, feed_dict=feed_dict)
# Reduce to a 1-dim array.
transfer_values = np.squeeze(transfer_values)
return transfer_values
########################################################################
# Batch-processing.
示例2: load_cached
# 需要导入模块: import cache [as 别名]
# 或者: from cache import cache [as 别名]
def load_cached(cache_path, in_dir):
"""
Wrapper-function for creating a DataSet-object, which will be
loaded from a cache-file if it already exists, otherwise a new
object will be created and saved to the cache-file.
This is useful if you need to ensure the ordering of the
filenames is consistent every time you load the data-set,
for example if you use the DataSet-object in combination
with Transfer Values saved to another cache-file, see e.g.
Tutorial #09 for an example of this.
:param cache_path:
File-path for the cache-file.
:param in_dir:
Root-dir for the files in the data-set.
This is an argument for the DataSet-init function.
:return:
The DataSet-object.
"""
print("Creating dataset from the files in: " + in_dir)
# If the object-instance for DataSet(in_dir=data_dir) already
# exists in the cache-file then reload it, otherwise create
# an object instance and save it to the cache-file for next time.
dataset = cache(cache_path=cache_path,
fn=DataSet, in_dir=in_dir)
return dataset
########################################################################
示例3: __init__
# 需要导入模块: import cache [as 别名]
# 或者: from cache import cache [as 别名]
def __init__(self, database):
self._web_handlers = {}
for c in get_all_classes(["web_handlers.py"], WebHandler):
obj = c(database, cache)
self._web_handlers[obj.url] = obj
self._web_server = Flask("web_server")
self._register(database)
示例4: _register
# 需要导入模块: import cache [as 别名]
# 或者: from cache import cache [as 别名]
def _register(self, database):
logger.info("Handlers register start !")
logger.info("Handler register: ")
for handler_name, handler_obj in self._web_handlers.items():
self._web_server.add_url_rule(
"/%s/<string:parameters>" % handler_name,
view_func=handler_obj.as_view(handler_name, database, cache)
)
logger.info("'%s' " % handler_name, False)
logger.info("Handlers register done !")
示例5: __init__
# 需要导入模块: import cache [as 别名]
# 或者: from cache import cache [as 别名]
def __init__(self, database):
self._database = database
self._articles = database.get_collection("article")
self._database_writers = {}
for c in get_all_classes(["database_writers.py"], DatabaseWriter):
obj = c(database, cache)
self._database_writers[obj.flag] = obj
self._file_path = ""
示例6: transfer_values_cache
# 需要导入模块: import cache [as 别名]
# 或者: from cache import cache [as 别名]
def transfer_values_cache(cache_path, model, images=None, image_paths=None):
"""
This function either loads the transfer-values if they have
already been calculated, otherwise it calculates the values
and saves them to a file that can be re-loaded again later.
Because the transfer-values can be expensive to compute, it can
be useful to cache the values through this function instead
of calling transfer_values() directly on the Inception model.
See Tutorial #08 for an example on how to use this function.
:param cache_path:
File containing the cached transfer-values for the images.
:param model:
Instance of the Inception model.
:param images:
4-dim array with images. [image_number, height, width, colour_channel]
:param image_paths:
Array of file-paths for images (must be jpeg-format).
:return:
The transfer-values from the Inception model for those images.
"""
# Helper-function for processing the images if the cache-file does not exist.
# This is needed because we cannot supply both fn=process_images
# and fn=model.transfer_values to the cache()-function.
def fn():
return process_images(fn=model.transfer_values, images=images, image_paths=image_paths)
# Read the transfer-values from a cache-file, or calculate them if the file does not exist.
transfer_values = cache(cache_path=cache_path, fn=fn)
return transfer_values
########################################################################
# Example usage.