<jupyter_start><jupyter_text>Convolutional Neural Networks---In this notebook, we generate a dataset from CIFAR-10 database.<jupyter_code>from torchvision import datasets
import torchvision.transforms as transforms
from sklearn.model_selection import train_test_split
import numpy as np
import pandas as pd 

def transform_trainNtest(seed = 224,testpercentage =0.2)
    #getting the normalized data from Torch.dataset

    transform = transforms.Compose([
        transforms.ToTensor(),
        transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
        ])

    train_data = datasets.CIFAR10('data', train=True,
                                  download=True, transform=transform)
    test_data = datasets.CIFAR10('data', train=False,
                                 download=True, transform=transform)
    #transform the X 
    #labels
    labelall = np.zeros(len(train_data)+len(test_data),dtype = 'int')
    datall = np.zeros((len(train_data)+len(test_data),3,32,32))
    for i in range(len(train_data)):
        datall[i,:,:,:] = np.expand_dims(train_data[i][0].numpy(),0)
        labelall[i] = train_data[i][1]
    for j in range(len(test_data)):
        #print(j)
        datall[len(train)+j,:,:,:] = np.expand_dims(test_data[j][0].numpy(),0)
        #print(j)
        labelall[len(train)+j] = int(test_data[j][1])
    
    np.random.seed(seed)
    x_train,x_test,y_train,y_test = train_test_split(datall,labelall,test_size = testpercentage,random_state=seed)
    np.save('cifar.train.npy',x_train)
    np.save('cifar.test.npy',x_test)
    np.save('cifar.trainlabel.npy',y_train)
        
    submissiondict = {'id': list(range(1,len(train_data)+len(test_data)+1)),
                  'class' : y_test}
    df = pd.DataFrame(submissiondict)
    print(df.head())
    df.to_csv('answer.csv',index=False) # This is the answer for HW 2
    print('Finish!!'')




sample = np.random.randint(10, size=12000)
submissiondict = {'id': list(range(1,12001)),
                  'class' : sample}
dfsub = pd.DataFrame(submissiondict)
dfsub.head()
dfsub.to_csv('sample_submission.csv',index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1445386064030132, 'fraction_numerical': 0.023540489642184557, 'mean_word_length': 3.521276595744681, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '655366', 'license': 'MIT', 'n_tokens_mistral': 780, 'n_tokens_neox': 739, 'n_words': 123, 'path': 'HW2_CNN/CIFAR_10_HWdata.ipynb', 'repo_name': 'MarcoXM/CS_6000_Deep_Learning', 'size': '2124'}