<jupyter_start><jupyter_text>Importing the libararies<jupyter_code>import fastai
import fastai.vision
from fastai.vision.all import *
import torch
import torchvision
import pandas as pd
import os
os.chdir('..')<jupyter_output><empty_output><jupyter_text>* Loading the csv file<jupyter_code>df=pd.read_csv('useful-csvs/refined-full.csv')<jupyter_output><empty_output><jupyter_text>* Making lables out of Style and Class<jupyter_code>train_df=df[['paths','style','CLASS']].copy()
len(train_df)
train_df['STYLcATG']=train_df['style']+','+train_df['CLASS']
train_df
len(train_df['STYLcATG'].unique())<jupyter_output><empty_output><jupyter_text>Top 30, are quite dense, so putting this as threshold<jupyter_code>train_df['STYLcATG'].value_counts()[:30]
selected_cats = (train_df.groupby('STYLcATG')['paths'].count().sort_values(ascending=False)[:30]).index
mapping_df = train_df[train_df['STYLcATG'].isin(selected_cats)]
len(mapping_df)<jupyter_output><empty_output><jupyter_text>We need to make it balanced  Best to make a balanced data,<jupyter_code>#mapping_df=train_df.copy()
#mapping_df = mapping_df[mapping_df['STYLcATG']=='Transitional,Chairs'].reset_index(drop=True)
g=mapping_df.copy()
g = g.groupby(['STYLcATG'])

g=pd.DataFrame(g.apply(lambda x: x.sample(g.size().min()).reset_index(drop=True)))

g.head()
g['STYLcATG'].value_counts()
final_training_df=g[['paths','STYLcATG']].copy()
len(final_training_df)
mapping_df=final_training_df.copy()
mapping_df.loc[mapping_df.sample(int(len(mapping_df)/5)).index,'is_valid'] = True
mapping_df['is_valid'] = mapping_df['is_valid'].fillna(False)

dls=ImageDataLoaders.from_df(mapping_df,path='TOTAL-DATA/full-data/',label_col=1,item_tfms=Resize(224),valid_col='is_valid')
dls.show_batch(max_n=9)
model = fastai.vision.models.vgg19_bn

learn = cnn_learner(dls,model, metrics=error_rate)#, metrics=partial(accuracy_multi, thresh=0.5)
learn.fine_tune(2)
learn.show_results()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16427104722792607, 'fraction_numerical': 0.008726899383983572, 'mean_word_length': 11.822368421052632, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '591573', 'license': 'Apache-2.0', 'n_tokens_mistral': 792, 'n_tokens_neox': 765, 'n_words': 88, 'path': 'Muhammad-Work/TrainingNotebooks/style_catgr.ipynb', 'repo_name': 'DmitriyG228/furniture', 'size': '1948'}