Created
December 1, 2021 07:10
-
-
Save cmastudios/7f29b6714a0936b900a1a7cd37cdf3f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"import scipy.misc\n", | |
"import skimage.io\n", | |
"import os\n", | |
"import cv2\n", | |
"\n", | |
"path = r\"C:\\Users\\Connor\\Downloads\\eoinf96-7-segmentdigitgenerator-e16f11b642a7\\images\"\n", | |
"\n", | |
"video = skimage.io.imread_collection(os.path.join(path, '*.png'), conserve_memory=True, plugin=None)\n", | |
"\n", | |
"features = np.zeros((len(video), 28*28 + 1), dtype=np.uint8)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"pycharm": { | |
"name": "#%%\n" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"labels = {f\"{i}\": i for i in range(10)}\n", | |
"\n", | |
"for i, filename in enumerate(video.files):\n", | |
" digit = os.path.basename(filename)[0]\n", | |
" label = labels[digit]\n", | |
" feature = video[i]\n", | |
" feature = cv2.resize(feature, (28, 28))\n", | |
" features[i, :-1] = feature.flatten()\n", | |
" features[i, -1] = label" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"pycharm": { | |
"name": "#%%\n" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"np.random.shuffle(features)\n", | |
"np.save(\"sevensegdataset\", features)\n", | |
"\n", | |
"## Want to do some future work?\n", | |
"## Download my dataset from https://www.reddit.com/r/MachineLearning/comments/j10ub1/p_like_mnist_but_for_7segment_displays/" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"pycharm": { | |
"name": "#%%\n" | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<matplotlib.image.AxesImage at 0x19ec2940520>" | |
] | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD4CAYAAAAq5pAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAARBklEQVR4nO3db2xd9XkH8O/35o8dkrDEmBgTEkIK7QgNSxsvpBtCFDoE0dSQF0MEVKVahFOpaKDxYih7UbQXE5vWskqbWsKImraMQtVGZBPbgMCWopWIJIT8hQWyBGI5cUOI8ocQx/GzFz7pDPg8xz7n3nuu/Xw/kmX7PPec83DjL+fe+zvn/GhmEJGxr1J2AyJSHwq7SBAKu0gQCrtIEAq7SBDj67mziWyyZkyu5y4bA+mXmyYW2ryd7XWKGm2J5GOcRq+dHfIPrlDYSd4O4PsAxgH4JzN71Ht8MybjBt5aZJejEpua3Hpl7uxC2+/f/15qzc6eLbRtGV0228bUWu6X8STHAfhHAHcAmAdgOcl5ebcnIrVV5D37IgDvmNl+M+sF8DMAS6vTlohUW5GwzwTw/qDfDyXLPoFkJ8ktJLecg15SipSl5p/Gm9kaM+sws44J8N+7ikjtFAl7F4BZg36/IlkmIg2oSNhfB3ANyatITgRwN4AN1WlLRKot99CbmfWRvB/Af2Bg6G2tme2uWmd1Nu6SFrduM2ek197+X3fdIysXuvU/+Vb6cMlwPPHaTam1yulx7rotO/1zAFq3Hs/T0v/vv+fD1Fpf9+FC25aRKTTObmbPA3i+Sr2ISA3pdFmRIBR2kSAUdpEgFHaRIBR2kSAUdpEg6no9eyPrP3XarVe6elJrnOJfo3/iK2fc+p+1vOnWp1Sa3frqP37brXt2L/N72372itzbBoDHD6SfA9C1Z3GhbRc5R4C9fe663m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DsSp677SSXlNTbLJKvkNxDcjfJB5LlpT53Tl91ed7q/p6d5DgA/wPgjwAcAvA6gOVmtqeujaQgeQBAh5mVfgIGyZsAnALwYzP7YrLsbwEcM7NHk/9RTjezv2iQ3h4BcKrsabyT2YraB08zDuBOAN9Eic+d09ddqMPzVsaRfRGAd8xsv5n1AvgZgKUl9NHwzGwTgGOfWrwUwLrk53UY+GOpu5TeGoKZdZvZtuTnkwAuTDNe6nPn9FUXZYR9JoD3B/1+CI0137sBeIHkVpKdZTczhLZB02wdBtBWZjNDyJzGu54+Nc14wzx3eaY/L0of0H3WjWb2ZQB3APh28nK1IdnAe7BGGjsd1jTe9TLENOO/VeZzl3f686LKCHsXgFmDfr8iWdYQzKwr+d4DYD0abyrqIxdm0E2+95Tcz2810jTeQ00zjgZ47sqc/ryMsL8O4BqSV5GcCOBuABtK6OMzSE5OPjgByckAbkPjTUW9AcCK5OcVAJ4rsZdPaJRpvNOmGUfJz13p05+bWd2/ACzBwCfy7wL4yzJ6SOlrLoA3k6/dZfcG4GkMvKw7h4HPNlYCuATARgD7ALwEoKWBevsJBqb23oGBYLWX1NuNGHiJvgPA9uRrSdnPndNXXZ43nS4rEoQ+oBMJQmEXCUJhFwlCYRcJQmEXCUJhFwlCYRcJ4v8A3FxXAy3Q8k4AAAAASUVORK5CYII=\n", | |
"text/plain": [ | |
"<Figure size 432x288 with 1 Axes>" | |
] | |
}, | |
"metadata": { | |
"needs_background": "light" | |
}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"import matplotlib.pyplot as plt\n", | |
"plt.imshow(features[696, :-1].reshape((28, 28)))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": { | |
"pycharm": { | |
"name": "#%%\n" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"from sklearn.ensemble import RandomForestClassifier\n", | |
"X = features[:, :-1]\n", | |
"Y = features[:, -1]\n", | |
"clf = RandomForestClassifier(n_estimators=10)\n", | |
"clf = clf.fit(X, Y)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": { | |
"pycharm": { | |
"name": "#%%\n" | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"1.0" | |
] | |
}, | |
"execution_count": 13, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"clf.score(X, Y)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": { | |
"pycharm": { | |
"name": "#%%\n" | |
} | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"['estimator.joblib']" | |
] | |
}, | |
"execution_count": 14, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"from joblib import dump, load\n", | |
"dump(clf, 'estimator.joblib')" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.8.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment