| |
| """Lab_10_640510710.ipynb |
| |
| Automatically generated by Colaboratory. |
| |
| Original file is located at |
| https://colab.research.google.com/drive/1Dg3wcofHEqoNIptakVwyhbpYSRv-1bgf |
| """ |
|
|
| from google.colab import drive |
|
|
| drive.mount('/content/gdrive') |
|
|
| !pip install -q kaggle |
| !mkdir ~/.kaggle |
| !cp /content/gdrive/MyDrive/kaggle.json ~/.kaggle/ |
| !kaggle datasets list |
|
|
| !kaggle datasets download -d mdwaquarazam/agricultural-crops-image-classification |
|
|
| !unzip /content/agricultural-crops-image-classification.zip |
|
|
| !python -m pip install transformers accelerate sentencepiece emoji pythainlp --quiet |
| !python -m pip install --no-deps thai2transformers==0.1.2 --quiet |
|
|
| from transformers import pipeline |
| from transformers import PerceiverFeatureExtractor, PerceiverForImageClassificationLearned |
| classifier = pipeline(task="image-classification") |
|
|
| classifier('/content/Agricultural-crops/banana/image (27).jpg') |
|
|
| from transformers import TrainingArguments |
|
|
| training_args = TrainingArguments(output_dir="test_trainer", |
| evaluation_strategy="epoch", |
| learning_rate=2e-5, |
| optim="adamw_torch") |
|
|
| from transformers import BertForSequenceClassification, BertTokenizer, AdamW, get_linear_schedule_with_warmup |
|
|
| |
| model = BertForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=len(dataset.classes)) |
|
|
| |
| tokenizer = BertTokenizer.from_pretrained('bert-base-uncased') |
|
|
| !python -m pip install huggingface_hub --quiet |
|
|
| !huggingface-cli login |
| !huggingface-cli repo create finetuned_yelp --type model |
|
|
| model.push_to_hub("finetuned_yelp") |
| tokenizer.push_to_hub("finetuned_yelp") |