Buy Me a Coffee☕
*My post explains Moving MNIST.
MovingMNIST() can use Moving MNIST dataset as shown below:
*Memos:
- The 1st argument is root(Required-Type:str or pathlib.Path). *An absolute or relative path is possible.
- The 2nd argument is split(Optional-Default:None-Type:str):
*Memos:
- None, "train" or "test" can be set to it.
- If it's None, all 20 frames(images) of each video are returned, ignoring split_ratio.
- The 3rd argument is split_ratio(Optional-Default:10-Type:int):
*Memos:
- If split is "train", data[:, :split_ratio] is returned.
- If split is "test", data[:, split_ratio:] is returned.
- If split is None, it's ignored. ignoring split_ratio.
- The 4th argument is transform(Optional-Default:None-Type:callable).
- The 5th argument is download(Optional-Default:False-Type:bool):
*Memos:
- If it's True, the dataset is downloaded from the internet to root.
- If it's True and the dataset is already downloaded, it's extracted.
- If it's True and the dataset is already downloaded, nothing happens.
- It should be False if the dataset is already downloaded because it's faster.
- You can manually download and extract the dataset from here to e.g. data/MovingMNIST/.
from torchvision.datasets import MovingMNIST all_data = MovingMNIST( root="data" ) all_data = MovingMNIST( root="data", split=None, split_ratio=10, download=False, transform=None ) train_data = MovingMNIST( root="data", split="train" ) test_data = MovingMNIST( root="data", split="test" ) len(all_data), len(train_data), len(test_data) # (10000, 10000, 10000) len(all_data[0]), len(train_data[0]), len(test_data[0]) # (20, 10, 10) all_data # Dataset MovingMNIST # Number of datapoints: 10000 # Root location: data all_data.root # 'data' print(all_data.split) # None all_data.split_ratio # 10 all_data.download # <bound method movingmnist.download of dataset movingmnist number datapoints: root location: data> print(all_data.transform) # None from torchvision.datasets import MovingMNIST import matplotlib.pyplot as plt plt.figure(figsize=(10, 3)) plt.subplot(1, 3, 1) plt.title("all_data") plt.imshow(all_data[0].squeeze()[0]) plt.subplot(1, 3, 2) plt.title("train_data") plt.imshow(train_data[0].squeeze()[0]) plt.subplot(1, 3, 3) plt.title("test_data") plt.imshow(test_data[0].squeeze()[0]) plt.show() </bound>
from torchvision.datasets import MovingMNIST all_data = MovingMNIST( root="data", split=None ) train_data = MovingMNIST( root="data", split="train" ) test_data = MovingMNIST( root="data", split="test" ) def show_images(data, main_title=None): plt.figure(figsize=(10, 8)) plt.suptitle(t=main_title, y=1.0, fontsize=14) for i, image in enumerate(data, start=1): plt.subplot(4, 5, i) plt.tight_layout(pad=1.0) plt.title(i) plt.imshow(image) plt.show() show_images(data=all_data[0].squeeze(), main_title="all_data") show_images(data=train_data[0].squeeze(), main_title="train_data") show_images(data=test_data[0].squeeze(), main_title="test_data")
from torchvision.datasets import MovingMNIST all_data = MovingMNIST( root="data", split=None ) train_data = MovingMNIST( root="data", split="train" ) test_data = MovingMNIST( root="data", split="test" ) import matplotlib.pyplot as plt def show_images(data, main_title=None): plt.figure(figsize=(10, 8)) plt.suptitle(t=main_title, y=1.0, fontsize=14) col = 5 for i, image in enumerate(data, start=1): plt.subplot(4, 5, i) plt.tight_layout(pad=1.0) plt.title(i) plt.imshow(image.squeeze()[0]) if i == col: break plt.show() show_images(data=all_data, main_title="all_data") show_images(data=train_data, main_title="train_data") show_images(data=test_data, main_title="test_data")
from torchvision.datasets import MovingMNIST import matplotlib.animation as animation all_data = MovingMNIST( root="data" ) import matplotlib.pyplot as plt from IPython.display import HTML figure, axis = plt.subplots() # ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ `ArtistAnimation()` ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ images = [] for image in all_data[0].squeeze(): images.append([axis.imshow(image)]) ani = animation.ArtistAnimation(fig=figure, artists=images, interval=100) # ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ `ArtistAnimation()` ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ # ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ `FuncAnimation()` ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ # def animate(i): # axis.imshow(all_data[0].squeeze()[i]) # # ani = animation.FuncAnimation(fig=figure, func=animate, # frames=20, interval=100) # ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ `FuncAnimation()` ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ # ani.save('result.gif') # Save the animation as a `.gif` file plt.ioff() # Hide a useless image # ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ Show animation ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ HTML(ani.to_jshtml()) # Animation operator # HTML(ani.to_html5_video()) # Animation video # ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ Show animation ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ # ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ Show animation ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ # plt.rcParams["animation.html"] = "jshtml" # Animation operator # plt.rcParams["animation.html"] = "html5" # Animation video # ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ Show animation ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
from torchvision.datasets import MovingMNIST from ipywidgets import interact, IntSlider all_data = MovingMNIST( root="data" ) import matplotlib.pyplot as plt from IPython.display import HTML def func(i): plt.imshow(all_data[0].squeeze()[i]) interact(func, i=(0, 19, 1)) # interact(func, i=IntSlider(min=0, max=19, step=1, value=0)) # ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ Set the start value ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ plt.show()
The above is the detailed content of MovingMNIST in PyTorch. For more information, please follow other related articles on the PHP Chinese website!

Is it enough to learn Python for two hours a day? It depends on your goals and learning methods. 1) Develop a clear learning plan, 2) Select appropriate learning resources and methods, 3) Practice and review and consolidate hands-on practice and review and consolidate, and you can gradually master the basic knowledge and advanced functions of Python during this period.

Key applications of Python in web development include the use of Django and Flask frameworks, API development, data analysis and visualization, machine learning and AI, and performance optimization. 1. Django and Flask framework: Django is suitable for rapid development of complex applications, and Flask is suitable for small or highly customized projects. 2. API development: Use Flask or DjangoRESTFramework to build RESTfulAPI. 3. Data analysis and visualization: Use Python to process data and display it through the web interface. 4. Machine Learning and AI: Python is used to build intelligent web applications. 5. Performance optimization: optimized through asynchronous programming, caching and code

Python is better than C in development efficiency, but C is higher in execution performance. 1. Python's concise syntax and rich libraries improve development efficiency. 2.C's compilation-type characteristics and hardware control improve execution performance. When making a choice, you need to weigh the development speed and execution efficiency based on project needs.

Python's real-world applications include data analytics, web development, artificial intelligence and automation. 1) In data analysis, Python uses Pandas and Matplotlib to process and visualize data. 2) In web development, Django and Flask frameworks simplify the creation of web applications. 3) In the field of artificial intelligence, TensorFlow and PyTorch are used to build and train models. 4) In terms of automation, Python scripts can be used for tasks such as copying files.

Python is widely used in data science, web development and automation scripting fields. 1) In data science, Python simplifies data processing and analysis through libraries such as NumPy and Pandas. 2) In web development, the Django and Flask frameworks enable developers to quickly build applications. 3) In automated scripts, Python's simplicity and standard library make it ideal.

Python's flexibility is reflected in multi-paradigm support and dynamic type systems, while ease of use comes from a simple syntax and rich standard library. 1. Flexibility: Supports object-oriented, functional and procedural programming, and dynamic type systems improve development efficiency. 2. Ease of use: The grammar is close to natural language, the standard library covers a wide range of functions, and simplifies the development process.

Python is highly favored for its simplicity and power, suitable for all needs from beginners to advanced developers. Its versatility is reflected in: 1) Easy to learn and use, simple syntax; 2) Rich libraries and frameworks, such as NumPy, Pandas, etc.; 3) Cross-platform support, which can be run on a variety of operating systems; 4) Suitable for scripting and automation tasks to improve work efficiency.

Yes, learn Python in two hours a day. 1. Develop a reasonable study plan, 2. Select the right learning resources, 3. Consolidate the knowledge learned through practice. These steps can help you master Python in a short time.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor