Compare commits
14 Commits
a201069006
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
f497756963
|
|||
|
0a597c5917
|
|||
|
03baa08d8a
|
|||
|
2a71605050
|
|||
|
702fe6cda6
|
|||
|
fc477ab15b
|
|||
|
628d9f171e
|
|||
|
6b81388d0e
|
|||
|
7bb921a482
|
|||
|
6135de00dd
|
|||
|
8489b2d5aa
|
|||
|
3f6ece863d
|
|||
|
deb41dfdc8
|
|||
|
73f8c867b7
|
+8
-28
@@ -38,34 +38,14 @@ from sklearn.metrics import confusion_matrix, classification_report
|
||||
# Fashion MNIST is built into Keras, downloads automatically on first run
|
||||
(X_train, y_train), (X_test, y_test) = tf.keras.datasets.fashion_mnist.load_data()
|
||||
|
||||
'''
|
||||
import numpy as np
|
||||
import gzip
|
||||
import os
|
||||
|
||||
def load_fashion_mnist(path):
|
||||
"""Load Fashion MNIST from local .gz files (Kaggle Zalando format)."""
|
||||
files = {
|
||||
'X_train': 'train-images-idx3-ubyte.gz',
|
||||
'y_train': 'train-labels-idx1-ubyte.gz',
|
||||
'X_test': 't10k-images-idx3-ubyte.gz',
|
||||
'y_test': 't10k-labels-idx1-ubyte.gz',
|
||||
}
|
||||
|
||||
with gzip.open(os.path.join(path, files['X_train'])) as f:
|
||||
X_train = np.frombuffer(f.read(), np.uint8, offset=16).reshape(-1, 28, 28)
|
||||
with gzip.open(os.path.join(path, files['y_train'])) as f:
|
||||
y_train = np.frombuffer(f.read(), np.uint8, offset=8)
|
||||
with gzip.open(os.path.join(path, files['X_test'])) as f:
|
||||
X_test = np.frombuffer(f.read(), np.uint8, offset=16).reshape(-1, 28, 28)
|
||||
with gzip.open(os.path.join(path, files['y_test'])) as f:
|
||||
y_test = np.frombuffer(f.read(), np.uint8, offset=8)
|
||||
|
||||
return (X_train, y_train), (X_test, y_test)
|
||||
|
||||
# Replace the Keras load line with:
|
||||
(X_train, y_train), (X_test, y_test) = load_fashion_mnist('./fashion-mnist/')
|
||||
'''
|
||||
# --- Offline alternative (comment out tf.keras line above and use this instead) ---
|
||||
# import pandas as pd
|
||||
# train_df = pd.read_csv('fashion-mnist_train.csv')
|
||||
# test_df = pd.read_csv('fashion-mnist_test.csv')
|
||||
# y_train = train_df['label'].values
|
||||
# y_test = test_df['label'].values
|
||||
# X_train = train_df.drop('label', axis=1).values.reshape(-1, 28, 28) # unflatten pixels to 28x28
|
||||
# X_test = test_df.drop('label', axis=1).values.reshape(-1, 28, 28)
|
||||
|
||||
print("Training set shape:", X_train.shape) # (60000, 28, 28)
|
||||
print("Test set shape: ", X_test.shape) # (10000, 28, 28)
|
||||
|
||||
@@ -51,58 +51,11 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": null,
|
||||
"id": "859cbc0f",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Training set shape: (60000, 28, 28)\n",
|
||||
"Test set shape: (10000, 28, 28)\n",
|
||||
"Classes: [0 1 2 3 4 5 6 7 8 9]\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# 2. Load Dataset\n",
|
||||
"# Fashion MNIST is built into Keras, downloads automatically on first run\n",
|
||||
"(X_train, y_train), (X_test, y_test) = tf.keras.datasets.fashion_mnist.load_data()\n",
|
||||
"\n",
|
||||
"'''\n",
|
||||
"import numpy as np\n",
|
||||
"import gzip\n",
|
||||
"import os\n",
|
||||
"\n",
|
||||
"def load_fashion_mnist(path):\n",
|
||||
" \"\"\"Load Fashion MNIST from local .gz files (Kaggle Zalando format).\"\"\"\n",
|
||||
" files = {\n",
|
||||
" 'X_train': 'train-images-idx3-ubyte.gz',\n",
|
||||
" 'y_train': 'train-labels-idx1-ubyte.gz',\n",
|
||||
" 'X_test': 't10k-images-idx3-ubyte.gz',\n",
|
||||
" 'y_test': 't10k-labels-idx1-ubyte.gz',\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" with gzip.open(os.path.join(path, files['X_train'])) as f:\n",
|
||||
" X_train = np.frombuffer(f.read(), np.uint8, offset=16).reshape(-1, 28, 28)\n",
|
||||
" with gzip.open(os.path.join(path, files['y_train'])) as f:\n",
|
||||
" y_train = np.frombuffer(f.read(), np.uint8, offset=8)\n",
|
||||
" with gzip.open(os.path.join(path, files['X_test'])) as f:\n",
|
||||
" X_test = np.frombuffer(f.read(), np.uint8, offset=16).reshape(-1, 28, 28)\n",
|
||||
" with gzip.open(os.path.join(path, files['y_test'])) as f:\n",
|
||||
" y_test = np.frombuffer(f.read(), np.uint8, offset=8)\n",
|
||||
"\n",
|
||||
" return (X_train, y_train), (X_test, y_test)\n",
|
||||
"\n",
|
||||
"# Replace the Keras load line with:\n",
|
||||
"(X_train, y_train), (X_test, y_test) = load_fashion_mnist('./fashion-mnist/')\n",
|
||||
"'''\n",
|
||||
"\n",
|
||||
"print(\"Training set shape:\", X_train.shape) # (60000, 28, 28)\n",
|
||||
"print(\"Test set shape: \", X_test.shape) # (10000, 28, 28)\n",
|
||||
"print(\"Classes:\", np.unique(y_train))"
|
||||
]
|
||||
"outputs": [],
|
||||
"source": "# 2. Load Dataset\n# Fashion MNIST is built into Keras — downloads automatically on first run\n(X_train, y_train), (X_test, y_test) = tf.keras.datasets.fashion_mnist.load_data()\n\n# --- Offline alternative (comment out tf.keras line above and use this instead) ---\n# import pandas as pd\n# train_df = pd.read_csv('fashion-mnist_train.csv')\n# test_df = pd.read_csv('fashion-mnist_test.csv')\n# y_train = train_df['label'].values\n# y_test = test_df['label'].values\n# X_train = train_df.drop('label', axis=1).values.reshape(-1, 28, 28) # unflatten pixels to 28x28\n# X_test = test_df.drop('label', axis=1).values.reshape(-1, 28, 28)\n\nprint(\"Training set shape:\", X_train.shape) # (60000, 28, 28)\nprint(\"Test set shape: \", X_test.shape) # (10000, 28, 28)\nprint(\"Classes:\", np.unique(y_train))"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
@@ -597,4 +550,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Reference in New Issue
Block a user