mnist stuff

This commit is contained in:
unknown 2024-10-17 18:19:47 +03:00
commit fdd9772173
3 changed files with 56 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
venv/

40
gen_stimulat.py Normal file
View File

@ -0,0 +1,40 @@
import numpy as np
from tensorflow.keras.datasets import mnist
import matplotlib.pyplot as plt
# Load the MNIST dataset
(x_train, y_train), (x_test, y_test) = mnist.load_data()
# Find the first '9' in the dataset
index_of_nine = np.where(y_train == 9)[0][0]
# Get the 28x28 pixel image of the number 9
image_of_nine = x_train[index_of_nine]
# Normalize the pixel values to [0, 1] range
normalized_image = image_of_nine / 255.0
# Function to convert a pixel value to an electrical stimulation level
def pixel_to_stimulation(pixel_value, max_stimulation=5.0):
"""
Converts a normalized pixel value (0.0 - 1.0) to an electrical stimulation (e.g., voltage).
Assumes max_stimulation is the maximum output voltage/current, e.g., 5V.
"""
return pixel_value * max_stimulation
# Apply the conversion to the entire image
stimulation_pattern = np.vectorize(pixel_to_stimulation)(normalized_image)
# Now `stimulation_pattern` is a 28x28 array of electrical stimulation levels (e.g., voltages)
print("Electrical stimulation pattern for '9':")
print(stimulation_pattern)
# Create a plot to visualize the stimulation pattern
plt.figure(figsize=(5, 5))
plt.imshow(stimulation_pattern, cmap='gray', interpolation='nearest')
plt.title("Electrical Stimulation Pattern for '9'")
plt.axis('off') # Hide the axis for a cleaner look
plt.show()
# Optionally, you could output this to an external device or system that applies electrical stimulation.

15
list_all_nines.py Normal file
View File

@ -0,0 +1,15 @@
# Load the MNIST dataset
from tensorflow.keras.datasets import mnist
import numpy as np
(x_train, y_train), (x_test, y_test) = mnist.load_data()
# Find all indices of the digit '9' in the training data
indices_of_nines = np.where(y_train == 9)[0]
# Count how many '9's are there in the training set
num_nines = len(indices_of_nines)
# Display the count
num_nines