{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"collapsed":true},"cell_type":"code","source":"import numpy as np\nimport cv2\nfrom skimage.feature import hog\nfrom sklearn import preprocessing\nfrom sklearn.svm import SVC\nfrom sklearn.datasets import fetch_openml\n# it works fine on pc but causing problem here to fetch this file\nmnist = fetch_openml(\"mnist_784\")\n\nX, y = mnist['data'], mnist['target']\ndata = np.array(X, 'int16')\ntarget = np.array(y, 'int')\nlist_hog = []\nfor feature in data:\n fd = hog(feature.reshape((28,28)), orientations=9, pixels_per_cell=(14,14),cells_per_block=(1,1),visualize=False )\n list_hog.append(fd)\nhog_features = np.array(list_hog, 'float64')\npreProcess = preprocessing.MaxAbsScaler().fit(hog_features)\nhog_features_transformed = preProcess.transform(hog_features)\nfrom sklearn.model_selection import train_test_split\nX_train, X_test, y_train, y_test = train_test_split(hog_features_transformed,target , random_state = 0)\nModel= SVC(C=3.0, kernel='rbf')\nprint(\"Training Started\")\nModel.fit(X_train, y_train)\nprint(\"Training Complete\")\nprint(Model.score(X_test, y_test))\n\n#Following code can be used to predict a digit after showing image that isnot part o\n\n#joblib.dump((Model, preProcess), \"ModelDigit42.pkl\", compress=3)\n#print(\"prediction has started\")\n#Model, preProcess = joblib.load(\"ModelDigit42.pkl\")\n#img = cv2.imread(\"test.jpg\")\n# Convert to grayscale and apply Gaussian filtering\n#im_grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n#im_gray = cv2.GaussianBlur(im_grey, (5, 5), 0)\n#ret, im_th = cv2.threshold(im_gray, 90, 255, cv2.THRESH_BINARY_INV)\n# Find contours in the image\n#ctrs,_ = cv2.findContours(im_th.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)\n# Get rectangles contains each contour\n#rects = [cv2.boundingRect(ctr) for ctr in ctrs]\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"clear","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}