How vzhou842/cnn-from-scratch works
Project Type & Purpose
• This project is an educational implementation of a Convolutional Neural Network (CNN), built from scratch for demonstration purposes. It also includes an alternative implementation using Keras.
• The goal is to illustrate the core operations involved in CNNs (convolution, pooling, softmax, etc.) with both a manual implementation and a framework-backed (Keras) version.
Analyzing the File Structure
• Top-level files:
• "cnn.py" likely defines the main execution of the hand-crafted CNN.
• "cnn_keras.py" provides an alternative implementation using Keras.
• "conv.py", "maxpool.py", and "softmax.py" likely contain the core building blocks/modules performing convolution operations, max pooling operations, and output (softmax) computations respectively.
• "requirements.txt" lists the dependencies needed.
• The absence of nested directories means the components are modularized within individual files rather than separated into distinct directories. Therefore, each file (module) plays a key role in the overall design.
Reviewing the README Insights
• The README describes the project as a hands-on walkthrough of CNN operations (forward-propagation only).
a. Main Components:
• Data Input / Preprocessing (implied in the main script, before data goes through the CNN layers)
• Convolution Module (handled by conv.py)
• Pooling Module (handled by maxpool.py)
• Fully-Connected & Softmax Module (using softmax.py)
• Two Control Flows: One representing the custom CNN (cnn.py) and another utilizing Keras (cnn_keras.py)
b. Relationships and Interactions:
• From there, data flows into the Convolution Module (conv.py) which applies convolutional filters.
• The output of convolution is then passed to a Pooling Module (maxpool.py) to reduce the spatial dimensions.
• The resulting feature maps are then forwarded to a Softmax or fully-connected layer (softmax.py) that produces the final classification probabilities.
• For the branch using Keras (cnn_keras.py), show that it wraps these concepts into a higher-level API but essentially follows the same sequence.
c. Important Architectural Patterns:
• The project adheres to a modular design where each computational step in the CNN is isolated in its own file/module.
• The design emulates the standard pipeline of forward propagation in CNNs.
• For the Keras version, note the abstraction provided by the framework, which encapsulates the operations into high-level functions.
• Separation of concerns: Each module (convolution, pooling, softmax) is responsible for its specific transformation, aligning with design principles of modularity and single responsibility.
d. Notable Technologies and Libraries:
• Python is the primary language used.
• Keras is leveraged in the "cnn_keras.py" implementation.