Tag: Rust
All the articles with the tag "Rust".
-
Building a Handwriting Input Method from Scratch: Preparation
Published date:Introduction to building a handwriting input method for Chinese characters from scratch, covering preparation steps, dataset selection, and technical approach using PyTorch for training, Rust Candle for inference, and WASM for deployment.
-
How to Access a Zip File as Conveniently as a Folder?
Published date:This article explains how to use FUSE to access a zip file as if it were a folder.
-
“Unsafe” Rust: Common Pitfalls in Rust
Published date:This article summarizes common security pitfalls in Rust development, including numeric conversions, integer overflows, array boundary access, oversized array handling, misuse of `unsafe`, time-of-check to time-of-use (TOCTOU) attacks, FFI risks, and circular references. By correctly using type-safe methods, limiting resource sizes, reducing the scope of `unsafe`, combining atomic operations, and managing memory, these issues can be effectively avoided.
-
Conversion of HEIF/HEIC Format Images to Other Image Formats
Published date:This article introduces methods for converting HEIF/HEIC format images, which suffer from poor compatibility due to patent issues related to HEVC technology. In Rust, HEIF images can be decoded using `libheif-rs` and converted to other formats via the `image` crate. On the frontend, similar functionality can be achieved with `heic-convert`, focusing on constructing buffer data that meets requirements for format conversion.
-
Rust's 'Uncommon but Super Useful' Syntaxes: How Many Do You Know?
Published date:This article introduces some uncommon but practical syntax features in Rust, including unions (`union`), slice pattern matching, raw pointer operations, inline assembly (`asm!`), extern blocks, loop return values, the `@` in match patterns, labeled loop control, never type (`!`), `#[repr]` attributes, and diverse macro invocation methods. These features can significantly enhance development efficiency and code flexibility in specific scenarios.
-
Rust Implementation of RMBG Inference
Published date:This article introduces how to implement RMBG (Remove Image Background) inference using Rust. By loading an ONNX model, it preprocesses the input image (resize, normalization), completes the model inference to generate a mask image, and uses the mask to remove the background or blend transparency. Finally, it optimizes the mask denormalization algorithm to improve background purity, suitable for use in fields like posters, games, etc.
-
Miscellaneous Features in Rust Candle
Published date:This article summarizes some miscellaneous features in the Rust Candle framework, including custom implementations of `masked_fill`, broadcasting mechanism (`broadcast_add`), matrix multiplication (`matmul` vs. element-wise multiplication), and an alternative implementation of the module container `ModuleList`. By comparing with PyTorch, it analyzes the differences and solutions in tensor operations and model loading in Candle.
-
Rust Large File Handling Comparison: Standard Library, Tokio, and Memory Mapping
Published date:This article compares three methods of handling large files in Rust: the standard library, Tokio, and memory mapping (mmap) in terms of memory usage. The standard library, which loads files all at once, consumes the most memory. Tokio significantly reduces memory usage through chunked optimization, while mmap, leveraging memory-mapped technology, uses almost no additional memory, offering the best performance.
-
Rust Candle Framework and PyTorch nn Module Network Layer Conversion (1)
Published date:This article compares the similarities and differences between Rust Candle and PyTorch in the implementation of neural network layers, covering sequential containers, convolutional layers (1D/2D and transposed convolution), pooling layers (max pooling and average pooling), and common activation functions. It focuses on analyzing the correspondence between the two in terms of functionality, parameter configuration, and usage, and points out that Candle does not yet support some features such as 3D convolution.
-
Rust Candle Framework and PyTorch nn Module Network Layer Conversion (2)
Published date:This article compares the implementation of common neural network layers in Rust Candle and PyTorch, including normalization layers (BatchNorm, LayerNorm, RMSNorm), recurrent layers (LSTM, GRU), Transformer, linear layers, Dropout layers, embedding layers, and upsampling layers. It summarizes the functional correspondence and differences between the two frameworks and highlights Candle's support for large model inference scenarios.
-
Reduction Operations in Rust Candle Framework and Pytorch Tensors
Published date:This article compares the implementation differences between Pytorch and Rust Candle framework for tensor reduction operations, covering common operations such as summation, mean, maximum, minimum, etc.
-
Pointwise Operations in Rust Candle Framework and Pytorch Tensors
Published date:This article compares the implementation differences between Pytorch and Rust Candle framework for pointwise tensor operations, covering common operations such as absolute value, trigonometric functions, exponentials, etc.