Build and train neural networks with TensorFlow
View on GitHubTheBushidoCollective/han
jutsu-tensorflow
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-tensorflow/skills/tensorflow-neural-networks/SKILL.md -a claude-code --skill tensorflow-neural-networksInstallation paths:
.claude/skills/tensorflow-neural-networks/# TensorFlow Neural Networks
Build and train neural networks using TensorFlow's high-level Keras API and low-level custom implementations. This skill covers everything from simple sequential models to complex custom architectures with multiple outputs, custom layers, and advanced training techniques.
## Sequential Models with Keras
The Sequential API provides the simplest way to build neural networks by stacking layers linearly.
### Basic Image Classification
```python
import tensorflow as tf
from tensorflow import keras
import numpy as np
# Load MNIST dataset
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
# Preprocess data
x_train = x_train.astype('float32') / 255.0
x_test = x_test.astype('float32') / 255.0
x_train = x_train.reshape(-1, 28 * 28)
x_test = x_test.reshape(-1, 28 * 28)
# Build Sequential model
model = keras.Sequential([
keras.layers.Dense(128, activation='relu', input_shape=(784,)),
keras.layers.Dropout(0.2),
keras.layers.Dense(64, activation='relu'),
keras.layers.Dropout(0.2),
keras.layers.Dense(10, activation='softmax')
])
# Compile model
model.compile(
optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy']
)
# Display model architecture
model.summary()
# Train model
history = model.fit(
x_train, y_train,
batch_size=32,
epochs=5,
validation_split=0.2,
verbose=1
)
# Evaluate model
test_loss, test_accuracy = model.evaluate(x_test, y_test, verbose=0)
print(f"Test accuracy: {test_accuracy:.4f}")
# Make predictions
predictions = model.predict(x_test[:5])
predicted_classes = np.argmax(predictions, axis=1)
print(f"Predicted classes: {predicted_classes}")
print(f"True classes: {y_test[:5]}")
# Save model
model.save('mnist_model.h5')
# Load model
loaded_model = keras.models.load_model('mnist_model.h5')
```
### Convolutional Neural Network
```python
def create_cnn_model(input_shape=(224, 224, 3), num_classes=1000):
"""Create CNN model for i