Spaces:
Build error
Build error
more update
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +1 -0
- .gitignore +2 -0
- S1_YoloTimber.py → S1_CNN_Model.py +4 -40
- app.py +3 -4
- data/annotations.csv +3 -0
- data/coco.yaml +3 -0
- data/dataset.yaml +3 -0
- data/image/test_full/Acrocarpus fraxinifolius/0744.JPG +3 -0
- data/image/test_full/Acrocarpus fraxinifolius/0745.JPG +3 -0
- data/image/test_full/Acrocarpus fraxinifolius/0746.JPG +3 -0
- data/image/test_full/Acrocarpus fraxinifolius/0747.JPG +3 -0
- data/image/test_full/Acrocarpus fraxinifolius/0748.JPG +3 -0
- data/image/test_full/Araucaria angustifolia/0257.JPG +3 -0
- data/image/test_full/Araucaria angustifolia/0258.JPG +3 -0
- data/image/test_full/Araucaria angustifolia/0259.JPG +3 -0
- data/image/test_full/Araucaria angustifolia/0260.JPG +3 -0
- data/image/test_full/Araucaria angustifolia/0261.JPG +3 -0
- data/image/test_full/Araucaria angustifolia/0262.JPG +3 -0
- data/image/test_full/Araucaria angustifolia/0263.JPG +3 -0
- data/image/test_full/Aspidosperma polyneuron/0148.JPG +3 -0
- data/image/test_full/Aspidosperma polyneuron/0149.JPG +3 -0
- data/image/test_full/Aspidosperma polyneuron/0150.JPG +3 -0
- data/image/test_full/Aspidosperma polyneuron/0151.JPG +3 -0
- data/image/test_full/Aspidosperma polyneuron/0152.JPG +3 -0
- data/image/test_full/Aspidosperma polyneuron/0153.JPG +3 -0
- data/image/test_full/Bagassa guianensis/2987.JPG +3 -0
- data/image/test_full/Bagassa guianensis/2988.JPG +3 -0
- data/image/test_full/Bagassa guianensis/2989.JPG +3 -0
- data/image/test_full/Bagassa guianensis/2990.JPG +3 -0
- data/image/test_full/Bagassa guianensis/2991.JPG +3 -0
- data/image/test_full/Bagassa guianensis/2992.JPG +3 -0
- data/image/test_full/Bagassa guianensis/2993.JPG +3 -0
- data/image/test_full/Bagassa guianensis/2994.JPG +3 -0
- data/image/test_full/Bagassa guianensis/2995.JPG +3 -0
- data/image/test_full/Bagassa guianensis/2996.JPG +3 -0
- data/image/test_full/Balfourodendron riedelianum/3556.JPG +3 -0
- data/image/test_full/Balfourodendron riedelianum/3557.JPG +3 -0
- data/image/test_full/Balfourodendron riedelianum/3558.JPG +3 -0
- data/image/test_full/Balfourodendron riedelianum/3559.JPG +3 -0
- data/image/test_full/Balfourodendron riedelianum/3560.JPG +3 -0
- data/image/test_full/Balfourodendron riedelianum/3561.JPG +3 -0
- data/image/test_full/Balfourodendron riedelianum/3562.JPG +3 -0
- data/image/test_full/Bertholethia excelsa/2190.JPG +3 -0
- data/image/test_full/Bertholethia excelsa/2191.JPG +3 -0
- data/image/test_full/Bertholethia excelsa/2192.JPG +3 -0
- data/image/test_full/Bertholethia excelsa/2193.JPG +3 -0
- data/image/test_full/Bertholethia excelsa/2194.JPG +3 -0
- data/image/test_full/Bertholethia excelsa/2195.JPG +3 -0
- data/image/test_full/Bertholethia excelsa/2196.JPG +3 -0
- data/image/test_full/Bertholethia excelsa/2197.JPG +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
data/** filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
test.*
|
| 2 |
+
*.pt
|
S1_YoloTimber.py → S1_CNN_Model.py
RENAMED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import torchvision
|
| 2 |
import torch
|
| 3 |
-
import hubconf
|
| 4 |
import os
|
| 5 |
from torch import nn, Tensor
|
| 6 |
import torch.nn.functional as F
|
|
@@ -8,27 +7,8 @@ import cv2
|
|
| 8 |
from PIL import Image
|
| 9 |
import numpy as np
|
| 10 |
|
| 11 |
-
model_name = "yolov6s"
|
| 12 |
-
|
| 13 |
-
from yolov6.models.yolo import Model as YoloModel
|
| 14 |
-
from yolov6.utils.config import Config
|
| 15 |
-
config = Config.fromfile(f"configs/base/{model_name}_base_finetune.py")
|
| 16 |
device=torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 17 |
|
| 18 |
-
class YoloBackbone(YoloModel):
|
| 19 |
-
def __init__(self, config, num_classes, device):
|
| 20 |
-
super().__init__(config, num_classes=num_classes)
|
| 21 |
-
|
| 22 |
-
self.to(device)
|
| 23 |
-
self.train()
|
| 24 |
-
|
| 25 |
-
def forward(self, x:Tensor) -> Tensor:
|
| 26 |
-
# x = self.backbone.forward(x)
|
| 27 |
-
# x = self.neck.forward(x)
|
| 28 |
-
# x = self.detect.forward(x)
|
| 29 |
-
# _,_,_,x = x
|
| 30 |
-
return x
|
| 31 |
-
|
| 32 |
class Interpreter(nn.Module):
|
| 33 |
def __init__(self,
|
| 34 |
class_count:int,
|
|
@@ -86,15 +66,13 @@ class Interpreter(nn.Module):
|
|
| 86 |
import patchify
|
| 87 |
from torchvision import transforms
|
| 88 |
|
| 89 |
-
class
|
| 90 |
def __init__(self,
|
| 91 |
image_size: tuple[int,int],
|
| 92 |
-
yolo_model: YoloBackbone,
|
| 93 |
interpreter: Interpreter,
|
| 94 |
):
|
| 95 |
super().__init__()
|
| 96 |
self.device = interpreter.device
|
| 97 |
-
self.yolo_model = yolo_model
|
| 98 |
self.image_size = image_size
|
| 99 |
self.interpreter = interpreter
|
| 100 |
|
|
@@ -111,7 +89,6 @@ class YoloTimber(nn.Module):
|
|
| 111 |
return preds
|
| 112 |
|
| 113 |
def forward(self, x:Tensor) -> Tensor:
|
| 114 |
-
x = self.yolo_model(x)
|
| 115 |
x = self.interpreter(x)
|
| 116 |
return x
|
| 117 |
|
|
@@ -138,33 +115,20 @@ class YoloTimber(nn.Module):
|
|
| 138 |
|
| 139 |
class_count = 41
|
| 140 |
|
| 141 |
-
def build_backbone(device=torch.device('cuda' if torch.cuda.is_available() else 'cpu')) -> YoloBackbone:
|
| 142 |
-
return YoloBackbone(
|
| 143 |
-
config = config,
|
| 144 |
-
num_classes=class_count,
|
| 145 |
-
device = device
|
| 146 |
-
)
|
| 147 |
-
|
| 148 |
def build_interpreter(img_size=(640,640),
|
| 149 |
-
yolo_model = None,
|
| 150 |
device=torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 151 |
) -> Interpreter:
|
| 152 |
img_size = list(img_size)
|
| 153 |
-
if yolo_model == None:
|
| 154 |
-
yolo_model = build_backbone(device)
|
| 155 |
|
| 156 |
x = torch.randn([3]+img_size).view([-1,3]+img_size).to(device)
|
| 157 |
-
x = yolo_model(x)
|
| 158 |
|
| 159 |
return Interpreter(class_count=class_count, sample_yolo_output=x, device=device)
|
| 160 |
|
| 161 |
def build_model(img_size = (640,640),
|
| 162 |
device=torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 163 |
-
) ->
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
image_size=img_size,
|
| 167 |
-
interpreter=build_interpreter(img_size, yolo_model, device))
|
| 168 |
|
| 169 |
if __name__ == "__main__":
|
| 170 |
model = build_model(img_size=(320,320))
|
|
|
|
| 1 |
import torchvision
|
| 2 |
import torch
|
|
|
|
| 3 |
import os
|
| 4 |
from torch import nn, Tensor
|
| 5 |
import torch.nn.functional as F
|
|
|
|
| 7 |
from PIL import Image
|
| 8 |
import numpy as np
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
device=torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
class Interpreter(nn.Module):
|
| 13 |
def __init__(self,
|
| 14 |
class_count:int,
|
|
|
|
| 66 |
import patchify
|
| 67 |
from torchvision import transforms
|
| 68 |
|
| 69 |
+
class CNN_Model(nn.Module):
|
| 70 |
def __init__(self,
|
| 71 |
image_size: tuple[int,int],
|
|
|
|
| 72 |
interpreter: Interpreter,
|
| 73 |
):
|
| 74 |
super().__init__()
|
| 75 |
self.device = interpreter.device
|
|
|
|
| 76 |
self.image_size = image_size
|
| 77 |
self.interpreter = interpreter
|
| 78 |
|
|
|
|
| 89 |
return preds
|
| 90 |
|
| 91 |
def forward(self, x:Tensor) -> Tensor:
|
|
|
|
| 92 |
x = self.interpreter(x)
|
| 93 |
return x
|
| 94 |
|
|
|
|
| 115 |
|
| 116 |
class_count = 41
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
def build_interpreter(img_size=(640,640),
|
|
|
|
| 119 |
device=torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 120 |
) -> Interpreter:
|
| 121 |
img_size = list(img_size)
|
|
|
|
|
|
|
| 122 |
|
| 123 |
x = torch.randn([3]+img_size).view([-1,3]+img_size).to(device)
|
|
|
|
| 124 |
|
| 125 |
return Interpreter(class_count=class_count, sample_yolo_output=x, device=device)
|
| 126 |
|
| 127 |
def build_model(img_size = (640,640),
|
| 128 |
device=torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 129 |
+
) -> CNN_Model:
|
| 130 |
+
return CNN_Model(image_size=img_size,
|
| 131 |
+
interpreter=build_interpreter(img_size, device))
|
|
|
|
|
|
|
| 132 |
|
| 133 |
if __name__ == "__main__":
|
| 134 |
model = build_model(img_size=(320,320))
|
app.py
CHANGED
|
@@ -1,21 +1,20 @@
|
|
| 1 |
import gdown
|
| 2 |
import os
|
| 3 |
import torch
|
| 4 |
-
from
|
| 5 |
import gradio as gr
|
| 6 |
import numpy as np
|
| 7 |
import cv2
|
| 8 |
import pandas as pd
|
| 9 |
|
| 10 |
-
MODEL_LINK = "https://drive.google.com/file/d/
|
| 11 |
MODEL_PATH = "model.pt"
|
| 12 |
|
| 13 |
if not os.path.exists(MODEL_PATH):
|
| 14 |
print("Downloading model . . . ")
|
| 15 |
gdown.download(MODEL_LINK,MODEL_PATH,fuzzy=True)
|
| 16 |
|
| 17 |
-
model:
|
| 18 |
-
model.image_size = (320,320)
|
| 19 |
|
| 20 |
def listdir_full(path: str) -> list[str]:
|
| 21 |
return [f"{path}/{p}" for p in os.listdir(path)]
|
|
|
|
| 1 |
import gdown
|
| 2 |
import os
|
| 3 |
import torch
|
| 4 |
+
from S1_CNN_Model import CNN_Model
|
| 5 |
import gradio as gr
|
| 6 |
import numpy as np
|
| 7 |
import cv2
|
| 8 |
import pandas as pd
|
| 9 |
|
| 10 |
+
MODEL_LINK = "https://drive.google.com/file/d/1YUTQlIjNEW8w7Y1kXCOlBNgrgTmdQBoI/view?usp=sharing"
|
| 11 |
MODEL_PATH = "model.pt"
|
| 12 |
|
| 13 |
if not os.path.exists(MODEL_PATH):
|
| 14 |
print("Downloading model . . . ")
|
| 15 |
gdown.download(MODEL_LINK,MODEL_PATH,fuzzy=True)
|
| 16 |
|
| 17 |
+
model:CNN_Model = torch.load(MODEL_PATH)
|
|
|
|
| 18 |
|
| 19 |
def listdir_full(path: str) -> list[str]:
|
| 20 |
return [f"{path}/{p}" for p in os.listdir(path)]
|
data/annotations.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:64dfe7d6b4be6d3efa7b52c5919eebb8068d53fba555f585b401ece80779db0f
|
| 3 |
+
size 81559
|
data/coco.yaml
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:65cc8c22fc16910f500b4dbfa1660dccabad9acc2bab1e670fd379c96a6aad72
|
| 3 |
+
size 1310
|
data/dataset.yaml
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:586efc12ccc267f70359b3fb245f93effe57891ca53734fb0f8d9c0c9d32c9b6
|
| 3 |
+
size 1258
|
data/image/test_full/Acrocarpus fraxinifolius/0744.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Acrocarpus fraxinifolius/0745.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Acrocarpus fraxinifolius/0746.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Acrocarpus fraxinifolius/0747.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Acrocarpus fraxinifolius/0748.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Araucaria angustifolia/0257.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Araucaria angustifolia/0258.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Araucaria angustifolia/0259.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Araucaria angustifolia/0260.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Araucaria angustifolia/0261.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Araucaria angustifolia/0262.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Araucaria angustifolia/0263.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Aspidosperma polyneuron/0148.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Aspidosperma polyneuron/0149.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Aspidosperma polyneuron/0150.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Aspidosperma polyneuron/0151.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Aspidosperma polyneuron/0152.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Aspidosperma polyneuron/0153.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bagassa guianensis/2987.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bagassa guianensis/2988.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bagassa guianensis/2989.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bagassa guianensis/2990.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bagassa guianensis/2991.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bagassa guianensis/2992.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bagassa guianensis/2993.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bagassa guianensis/2994.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bagassa guianensis/2995.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bagassa guianensis/2996.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Balfourodendron riedelianum/3556.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Balfourodendron riedelianum/3557.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Balfourodendron riedelianum/3558.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Balfourodendron riedelianum/3559.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Balfourodendron riedelianum/3560.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Balfourodendron riedelianum/3561.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Balfourodendron riedelianum/3562.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bertholethia excelsa/2190.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bertholethia excelsa/2191.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bertholethia excelsa/2192.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bertholethia excelsa/2193.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bertholethia excelsa/2194.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bertholethia excelsa/2195.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bertholethia excelsa/2196.JPG
ADDED
|
|
Git LFS Details
|
data/image/test_full/Bertholethia excelsa/2197.JPG
ADDED
|
|
Git LFS Details
|