学习内容整理

2023/01/03

Epoch vs Batch Size vs Iterations

Epochs: One Epoch is when an ENTIRE dataset is passed forward and backward through the neural network only ONCE.

Batch: divide a whole dataset into Number of Batches or sets or parts.

Batch Size: Total number of training examples present in a single batch.

Iterations: the number of batches needed to complete one epoch.

For example, We can divide the dataset of 2000 examples into batches of 500 then it will take 4 iterations to complete 1 epoch.

With Statement in python

Together with context manager, with statement is used in exception handling to make the code cleaner and much more readable, and simplifies the management of common resources like file streams.

Take an example of the construction of a context manager and the use of with statement:

# a simple file writer object

class MessageWriter(object):
    def __init__(self, file_name):
        self.file_name = file_name
    
    def __enter__(self):
        self.file = open(self.file_name, 'w')
        return self.file

    def __exit__(self, *args):
        self.file.close()

# using with statement with MessageWriter

with MessageWriter('my_file.txt') as xfile:
    xfile.write('hello world')

The statement after with can be regarded as a common line of code, but since it is one kind of context manager, the __enter__ method needs to be run when executing, and the __exit__ mechod needs to be run at the end of the entire code block.

Context Manager

The interface of __enter__() and __exit__() methods which provides the support of with statement in user defined objects is called Context Manager.

Two ways to construct a context manager:

  • Class based context manager

  • Contextlib module based decorator

Yield Statement and Generator Function

Yield Statement: The yield statement suspends a function's execution and sends a value back to the caller, but retains enough state to enable the function to resume where it left off. When the function resumes, it continues execution immediately after the last yield run. This allows its code to produce a series of values over time, rather than computing them at once and sending them back like a list.

Generator-Function: A generator-function is defined like a normal function, but whenever it needs to generate a value, it does so with the yield keyword rather than return. If the body of a def contains yield, the function automatically becomes a generator function.

Decorators

Decorators: It allows programmers to modify the behaviour of a function or class. Decorators allow us to wrap another function in order to extend the behaviour of the wrapped function, without permanently modifying it.

Iterators and Iterable

Iterator in Python is an object that is used to iterate over iterable objects like lists, tuples, dicts, and sets. The iterator object is initialized using the iter() method. It uses the next() method for iteration.

First class functions

First class objects: First class objects in a language are handled uniformly throughout. They may be stored in data structures, passed as arguments, or used in control structures.

First class functions: A programming language, python for example, is said to support first-class functions if it treats functions as first-class objects.

properties of first class functions:

  • A function is an instance of the Object type.

  • You can store the function in a variable.

  • You can pass the function as a parameter to another function.

  • You can return the function from a function.

  • You can store them in data structures such as hash tables, lists, …

2023/01/04

require_grade and torch.set_grad_enabled()

require_grade: In PyTorch, the requires_grad attribute of a tensor specifies whether gradients with respect to the tensor should be computed and stored in the tensor's .grad attribute during the backward pass of a training iteration. This is used to enable or disable gradient computation for specific tensors.

torch.set_grad_enabled(): This context manager is used to prevent calculating gradients in the following code block. It is used to evaluate the model and doesn't need to call backward() to calculate the gradients and update the corresponding parameters.

2023/01/19

grep command

grep is a command-line utility for searching plain-text data sets for lines that match a regular expression. Its name comes from the ed command g/re/p (globally search for a regular expression and print matching lines), which has the same effect. grep was originally developed for the Unix operating system, but later available for all Unix-like systems and some others such as OS-9.

X-server

Most Ubuntu systems come with a built-in X-server, which is the software component that handles the graphical display of applications. X-server is the component that allows applications to display their graphical output on the screen, it is required to run GUI-based applications on Linux systems.

X-server is included as part of the standard Ubuntu installation, so most Ubuntu systems will have an X-server installed by default. However, some Ubuntu servers or minimal installations may not have the X-server installed, as it may not be required for the specific use case.

You can check if your Ubuntu system has an X-server installed by running the following command in a terminal:

dpkg -l | grep xserver-xorg

2023/01/20

Common Abreviations

i. e.: Abreviation of "id est", which means "that is (to say)". /ɪd ɛst/

e. g.: Abreviation of "exempli gratia", which means "for example". /ɪɡˈzempli ˈɡreiʃiə/

Lookup Table and Colormap

Lookup table (LUT) is one kind of data structure in computer science. It's an array that replaces runtime computation with a simpler array indexing operation. The process is termed as "direct addressing".

In the aspect of image processing, an LUT is simply a table of cross-references linking index numbers to output values to determine the colors and intensity values with which a particular image will be displayed, and in this context the LUT is often called simply a colormap.

Advantages of using LUTs:

  • Save storage space. The index number can be made to use fewer bits than the output value.

  • Experiment easily with different colors labling schemes.

Disadvantages of using LUTs:

  • Introduce additional complexity into an image format. It is usually necessary for each image to carry around its own colormap, and this LUT must be continually consulted whenever the image is displayed or processed.

  • Color quantization is lossy.

你可能感兴趣的:(学习记录,python,深度学习,学习,python,人工智能,深度学习,经验分享)