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
from fastai.vision import * | |
from fastai.vision.models import resnet50 |
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
tfms = get_transforms(do_flip=True, flip_vert=True, max_rotate=50, max_lighting=0.1, max_warp=0 ) | |
data = ImageDataBunch.from_df('/content/drive/MyDrive/CV_Vehicle_classification/train_data/images', train, ds_tfms=tfms, label_delim= None, valid_pct=0.2, fn_col=0, label_col=1 , size=299,bs=64).normalize(imagenet_stats) |
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
t_cnn1 = cnn_learner(data, resnet50, pretrained=True, metrics=[accuracy]) | |
t_cnn1.fit_one_cycle(5) |
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
t_cnn1.unfreeze() | |
t_cnn1.fit_one_cycle(8) |
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
t_cnn1.lr_find() | |
t_cnn1.recorder.plot() | |
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
t_cnn1.fit_one_cycle(10,max_lr=slice(1e-5, 1e-4)) | |
t_cnn1.freeze() | |
t_cnn1.export('/content/drive/MyDrive/CV_Vehicle_classification/model/Bmodel_fastai_resnet50.h5') |
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
test_data = ImageList.from_df(test, cols=['image_names'], path='/content/drive/MyDrive/CV_Vehicle_classification/train_data/images') | |
t_rn50 = load_learner('/content/drive/MyDrive/CV_Vehicle_classification/model/', 'Bmodel_fastai_resnet50.h5', test = test_data) | |
y_trn50 = t_rn50.TTA(ds_type = DatasetType.Test) | |
preds = y_trn50[0].argmax(-1) |
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
import gensim | |
from gensim import corpora | |
text1 = ["""Gensim is a free open-source Python library for representing documents as semantic vectors, | |
as efficiently and painlessly as possible. Gensim is designed | |
to process raw, unstructured digital texts using unsupervised machine learning algorithms."""] | |
tokens1 = [[item for item in line.split()] for line in text1] | |
g_dict1 = corpora.Dictionary(tokens1) |
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
from gensim.utils import simple_preprocess | |
from gensim import corpora | |
text2 = open('sample_text.txt', encoding ='utf-8') | |
tokens2 =[] | |
for line in text2.read().split('.'): | |
tokens2.append(simple_preprocess(line, deacc = True)) | |
g_dict2 = corpora.Dictionary(tokens2) |
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
g_dict1.add_documents(tokens2) | |
print("The dictionary has: " +str(len(g_dict1)) + " tokens\n") | |
print(g_dict1.token2id) |
OlderNewer