Zai commited on
Commit
e73a5f7
1 Parent(s): 702ff8a

updated dataset and filenames

Browse files
.github/workflows/hugging-face.yaml CHANGED
@@ -12,7 +12,33 @@ jobs:
12
  with:
13
  fetch-depth: 0
14
  lfs: true
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  - name: Push to hub
16
  env:
17
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
18
- run: git push https://zaibutcooler:[email protected]/spaces/zaibutcooler/headshot --force main
 
 
12
  with:
13
  fetch-depth: 0
14
  lfs: true
15
+ - name: Set Git identity
16
+ run: |
17
+ git config --global user.email "[email protected]"
18
+ git config --global user.name "GitHub Actions"
19
+
20
+ - name: Update README.md
21
+ run: |
22
+ tmp_file=$(mktemp)
23
+ echo "---" >> $tmp_file
24
+ echo "title: Headshot" >> $tmp_file
25
+ echo "emoji: 🏹" >> $tmp_file
26
+ echo "colorFrom: purple" >> $tmp_file
27
+ echo "colorTo: blue" >> $tmp_file
28
+ echo "sdk: streamlit" >> $tmp_file
29
+ echo "sdk_version: 1.29.0" >> $tmp_file
30
+ echo "app_file: space.py" >> $tmp_file
31
+ echo "pinned: false" >> $tmp_file
32
+ echo "license: openrail" >> $tmp_file
33
+ echo "---" >> $tmp_file
34
+ echo "" >> $tmp_file
35
+ cat README.md >> $tmp_file
36
+ mv $tmp_file README.md
37
+ git add README.md
38
+ git commit -m "Updated README.md"
39
+
40
  - name: Push to hub
41
  env:
42
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
43
+ run: |
44
+ git push https://zaibutcooler:[email protected]/spaces/zaibutcooler/headshot --force main
README.md CHANGED
@@ -1,15 +1,2 @@
1
- ---
2
-
3
- title: Headshot
4
- emoji: ✨
5
- colorFrom: purple
6
- colorTo: blue
7
- sdk: streamlit
8
- sdk_version: 1.29.0
9
- app_file: space.py
10
- pinned: false
11
- license: openrail
12
- ---
13
-
14
 
15
  # Headshot Project
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
  # Headshot Project
headshot/__init__.py CHANGED
@@ -1,2 +1 @@
1
- from headshot.headshot import Headshot
2
- from .config import Config
 
1
+ from headshot.model import Model
 
headshot/__main__.py ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ if __name__ == "__main__":
2
+ print("Main Function")
headshot/config.py CHANGED
@@ -1,6 +1,9 @@
1
- class Config:
2
- def __init__(self) -> None:
3
- pass
4
-
5
 
6
- config = Config()
 
 
 
 
 
 
 
1
+ import torch
 
 
 
2
 
3
+ class Config:
4
+ def __init__(self,num_epoch=20,lr=0.02) -> None:
5
+ self.num_epoch = num_epoch
6
+ self.lr = lr
7
+ self.device ='cuda' if torch.cuda.is_available() else 'cpu'
8
+
9
+ base_config = Config()
headshot/{data_prep.py → dataset.py} RENAMED
@@ -1,29 +1,19 @@
1
  import torch
2
- from torch.utils.data import DataLoader, Dataset
 
3
  from torchvision import transforms, datasets
4
  from datasets import load_dataset
5
 
6
- class FaceDataset(Dataset):
7
  def __init__(self):
8
- self.tranforms = transforms.Compose([
9
-
10
- ])
11
 
12
- self.data = None
13
-
14
 
15
  def __len__(self):
16
  return len(self.data)
17
 
18
- def download_data(self):
19
- loaded_data = load_dataset('zaibutcooler/chimpanzees')
20
- self.data = loaded_data
21
-
22
  def __getitem__(self, idx):
23
- # Load and preprocess the image at the given index
24
- image = self.data[idx]
25
- label = self.labels[idx]
26
-
27
-
28
- image = self.transform(image)
29
  return image,label
 
1
  import torch
2
+ from torch.utils.data import DataLoader
3
+ from torch.utils.data import Dataset as HfDataset
4
  from torchvision import transforms, datasets
5
  from datasets import load_dataset
6
 
7
+ class Dataset(HfDataset):
8
  def __init__(self):
9
+ self.loaded_data = load_dataset('zaibutcooler/chimp-detection')
 
 
10
 
11
+ self.images = self.loaded_data['image']
12
+ self.labels = self.loaded_data['faces']
13
 
14
  def __len__(self):
15
  return len(self.data)
16
 
 
 
 
 
17
  def __getitem__(self, idx):
18
+ image,label = self.images[idx],self.labels[idx]
 
 
 
 
 
19
  return image,label
headshot/headshot.py DELETED
@@ -1,48 +0,0 @@
1
- import torch
2
- from torch import nn
3
- from .data_prep import FaceDataset
4
-
5
- class Headshot(nn.Module):
6
- def __init__(self,num_epoch=20,lr=0.02):
7
- super().__init__()
8
- # self.dataset = FaceDataset()
9
- self.num_epoch = num_epoch
10
- self.lr = lr
11
- self.device = 'cuda' if torch.cuda.is_available() else 'cpu'
12
-
13
- self.layer = nn.Sequential(
14
-
15
- )
16
-
17
-
18
- def forward(self,x):
19
- out = self.layer
20
- return out
21
-
22
- def train(self):
23
- loss_fn = nn.CrossEntropyLoss()
24
- optimizer = torch.optim.Adam(self.parameters(),lr=self.lr)
25
- for epoch in range(self.num_epoch):
26
- for i,(image,label) in enumerate(self.dataset):
27
- image,label = image.to(self.device),label.to(self.device)
28
-
29
- optimizer.zero_grad()
30
-
31
- output = self(image)
32
- loss = loss_fn(output,label)
33
- loss.backward()
34
- optimizer.step()
35
- print(f"epoch {epoch} loss:{loss.item()}")
36
-
37
-
38
- def predict_image(self,image):
39
- points = self.forward(image)
40
-
41
- def predict_video(self,video):
42
- pass
43
-
44
- def load_pretrain(self,name=""):
45
- pretrained = torch.load(pretrained)
46
- self.load_state_dict(pretrained)
47
-
48
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
headshot/model.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from torch import nn
3
+ from .dataset import Dataset
4
+ from .config import Config
5
+ from huggingface_hub import PyTorchModelHubMixin
6
+ import huggingface_hub
7
+
8
+ class Model(nn.Module,PyTorchModelHubMixin):
9
+ def __init__(self,config:Config):
10
+ super().__init__()
11
+ self.config = config
12
+ self.num_epoch = config.num_epoch
13
+ self.lr = config.lr
14
+ self.device = config.device
15
+
16
+ # TODO start training
17
+ self.layer = nn.Sequential(
18
+
19
+ )
20
+
21
+
22
+ def forward(self,x):
23
+ out = self.layer
24
+ return out
25
+
26
+ def save_pretrained(self, name="headshot",username="zaibutcooler"):
27
+ # self.model.save_pretrained(name)
28
+ self.model.push_to_hub(f"{username}/{name}")
29
+ print("Successfully saved the pretrainied")
30
+
31
+ def load_pretrained(self, url="zaibutcooler/headshot"):
32
+ self.model = self.gpt.from_pretrained(url)
33
+ print("Successfully loaded the pretrained")
34
+
35
+ def huggingface_login(self, token):
36
+ assert token is not None
37
+ huggingface_hub.login(token=token)
38
+ print("Logged in successfully")
39
+
40
+
headshot/robot.py DELETED
@@ -1,16 +0,0 @@
1
- # to connect with some physical machine
2
- from pyrobot import Robot
3
-
4
- # Initialize the robot
5
- robot = Robot('locobot')
6
-
7
- def move_forward(distance):
8
- # Move the robot forward
9
- robot.base.go_to_relative([distance, 0, 0])
10
-
11
- if __name__ == "__main__":
12
- # Define the displacement (in meters) for the robot to move forward
13
- forward_distance = 0.5 # Move 0.5 meters forward
14
-
15
- # Move the robot forward
16
- move_forward(forward_distance)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
robot/robot.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from headshot import Model