Python cache.cache() Examples
The following are 15
code examples of cache.cache().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cache
, or try the search function
.
Example #1
Source File: inception.py From Deep-Learning-By-Example with MIT License | 5 votes |
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.
Example #2
Source File: dataset.py From Deep-Learning-By-Example with MIT License | 5 votes |
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 ########################################################################
Example #3
Source File: web_server.py From BlogReworkPro with GNU General Public License v3.0 | 5 votes |
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)
Example #4
Source File: web_server.py From BlogReworkPro with GNU General Public License v3.0 | 5 votes |
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 !")
Example #5
Source File: writer.py From BlogReworkPro with GNU General Public License v3.0 | 5 votes |
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 = ""
Example #6
Source File: inception.py From models with Apache License 2.0 | 5 votes |
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.
Example #7
Source File: dataset.py From MachineLearning_TensorFlow with MIT License | 5 votes |
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 ########################################################################
Example #8
Source File: inception.py From MachineLearning_TensorFlow with MIT License | 5 votes |
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.
Example #9
Source File: dataset.py From MachineLearning_TensorFlow with MIT License | 5 votes |
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 ########################################################################
Example #10
Source File: inception.py From MachineLearning_TensorFlow with MIT License | 5 votes |
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.
Example #11
Source File: inception.py From curriculum_learning with GNU General Public License v3.0 | 5 votes |
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.
Example #12
Source File: inception.py From Deep-Learning-By-Example with MIT License | 4 votes |
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.
Example #13
Source File: inception.py From models with Apache License 2.0 | 4 votes |
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.
Example #14
Source File: inception.py From MachineLearning_TensorFlow with MIT License | 4 votes |
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.
Example #15
Source File: inception.py From curriculum_learning with GNU General Public License v3.0 | 4 votes |
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.