kmlf commited on
Commit
8028ced
·
1 Parent(s): 91e6570

Upload lab_10_640510710 (1).py

Browse files
Files changed (1) hide show
  1. lab_10_640510710 (1).py +53 -0
lab_10_640510710 (1).py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """Lab_10_640510710.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1Dg3wcofHEqoNIptakVwyhbpYSRv-1bgf
8
+ """
9
+
10
+ from google.colab import drive
11
+
12
+ drive.mount('/content/gdrive')
13
+
14
+ !pip install -q kaggle
15
+ !mkdir ~/.kaggle
16
+ !cp /content/gdrive/MyDrive/kaggle.json ~/.kaggle/
17
+ !kaggle datasets list
18
+
19
+ !kaggle datasets download -d mdwaquarazam/agricultural-crops-image-classification
20
+
21
+ !unzip /content/agricultural-crops-image-classification.zip
22
+
23
+ !python -m pip install transformers accelerate sentencepiece emoji pythainlp --quiet
24
+ !python -m pip install --no-deps thai2transformers==0.1.2 --quiet
25
+
26
+ from transformers import pipeline
27
+ from transformers import PerceiverFeatureExtractor, PerceiverForImageClassificationLearned
28
+ classifier = pipeline(task="image-classification")
29
+
30
+ classifier('/content/Agricultural-crops/banana/image (27).jpg')
31
+
32
+ from transformers import TrainingArguments
33
+
34
+ training_args = TrainingArguments(output_dir="test_trainer",
35
+ evaluation_strategy="epoch",
36
+ learning_rate=2e-5,
37
+ optim="adamw_torch")
38
+
39
+ from transformers import BertForSequenceClassification, BertTokenizer, AdamW, get_linear_schedule_with_warmup
40
+
41
+ # โมเดล BERT สำหรับจำแนกประเภท
42
+ model = BertForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=len(dataset.classes))
43
+
44
+ # ใช้ tokenizer ของ BERT
45
+ tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
46
+
47
+ !python -m pip install huggingface_hub --quiet
48
+
49
+ !huggingface-cli login
50
+ !huggingface-cli repo create finetuned_yelp --type model
51
+
52
+ model.push_to_hub("finetuned_yelp")
53
+ tokenizer.push_to_hub("finetuned_yelp")