<jupyter_start><jupyter_text><jupyter_code>!pip install fastai -q --upgrade
from fastai.vision.all import *
import numpy as np
import pandas as pd
import os
from pathlib import Path
from PIL import Image
import matplotlib.pyplot as plt
# create the .kaggle directory and an empty kaggle.json file
!mkdir -p /root/.kaggle
!touch /root/.kaggle/kaggle.json
!chmod 600 /root/.kaggle/kaggle.json
import json
kaggle_username = "korycallanan"
kaggle_key = "<KEY>"

with open("/root/.kaggle/kaggle.json", "w") as f:
    f.write(json.dumps({"username": kaggle_username, "key": kaggle_key}))
!kaggle datasets download -d datamunge/sign-language-mnist
!unzip -o sign-language-mnist.zip
path = Path('sign-language-mnist')
path.ls()
TRAIN_DIR = path/'sign_mnist_train'/'sign_mnist_train.csv'
TEST_DIR = path/'sign_mnist_test'/'sign_mnist_test.csv'
train = pd.read_csv(TRAIN_DIR)
test = pd.read_csv(TEST_DIR)
train.head()
def get_images(df):
    IMG_WIDTH =28
    IMG_HEIGHT=28
    
    df['img'] = df[df.columns[df.columns.str.startswith('pixel')]].apply(
        lambda x: PILImage(Image.fromarray(np.array(x.values).reshape((IMG_WIDTH,IMG_HEIGHT)).astype(np.uint8))),
        axis=1
    )
    
    return df[df.columns[[not x for x in df.columns.str.startswith('pixel')]]]
train_df = get_images(train)
def get_x(r): return r['img']
def get_y(r): return r['label']
dblock = DataBlock(blocks=(ImageBlock, CategoryBlock), get_x = get_x, get_y=get_y)
dls = dblock.dataloaders(train_df)
learn = cnn_learner(dls, resnet34, metrics=error_rate).to_fp16()
learn.fine_tune(10)<jupyter_output>Downloading: "https://download.pytorch.org/models/resnet34-b627a593.pth" to /root/.cache/torch/hub/checkpoints/resnet34-b627a593.pth
{'fraction_non_alphanumeric': 0.14386376981796828, 'fraction_numerical': 0.0182031708749266, 'mean_word_length': 5.1516245487364625, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '205436', 'license': 'MIT', 'n_tokens_mistral': 690, 'n_tokens_neox': 668, 'n_words': 126, 'path': 'Prototype.ipynb', 'repo_name': 'koryca/mec-final-project', 'size': '1730'}