Compare commits
3 Commits
master
...
s481876-pa
Author | SHA1 | Date | |
---|---|---|---|
df9fa479c6 | |||
a024da6e00 | |||
ae893f20d8 |
@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="accountSettings">
|
||||
<option name="activeRegion" value="us-east-1" />
|
||||
<option name="recentlyUsedRegions">
|
||||
<list>
|
||||
<option value="us-east-1" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.11 (ai-wozek) (2)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (ai-wozek)" project-jdk-type="Python SDK" />
|
||||
</project>
|
@ -1,24 +1,18 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="wozek" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
|
||||
<module name="wozek" />
|
||||
<option name="ENV_FILES" value="" />
|
||||
<option name="INTERPRETER_OPTIONS" value="" />
|
||||
<option name="PARENT_ENVS" value="true" />
|
||||
<envs>
|
||||
<env name="PYTHONUNBUFFERED" value="1" />
|
||||
</envs>
|
||||
<option name="SDK_HOME" value="" />
|
||||
<option name="SDK_NAME" value="Python 3.11 (ai-wozek) (2)" />
|
||||
<option name="SDK_NAME" value="Python 3.10" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<option name="IS_MODULE_SDK" value="false" />
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
|
||||
<EXTENSION ID="software.aws.toolkits.jetbrains.core.execution.PythonAwsConnectionExtension">
|
||||
<option name="credential" />
|
||||
<option name="region" />
|
||||
<option name="useCurrentConnection" value="false" />
|
||||
</EXTENSION>
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/wozek.py" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||
|
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -1,10 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -1 +0,0 @@
|
||||
,DESKTOP-REF7T1M/abc,DESKTOP-REF7T1M,16.06.2024 22:58,file:///C:/Users/abc/AppData/Roaming/LibreOffice/4;
|
@ -1,31 +1,12 @@
|
||||
import random
|
||||
from glob import glob
|
||||
import numpy as np
|
||||
|
||||
|
||||
class Cargo:
|
||||
def __init__(self, height,width,depth,weight,damage,label_state,content,value,position):
|
||||
self.height=height
|
||||
self.width=width
|
||||
self.depth=depth
|
||||
def __init__(self, name, category, size, weight):
|
||||
self.name = name
|
||||
self.size = size
|
||||
self.weight = weight
|
||||
self.damage=damage
|
||||
self.label_state=label_state
|
||||
self.content=content
|
||||
self.value=value
|
||||
self.position=position
|
||||
def contentSplit(self):
|
||||
if self.content=='fruits':
|
||||
test=glob('./siec/train/fragile/*')
|
||||
self.image=np.random.choice(test)
|
||||
elif self.content=='nuclear_waste':
|
||||
test=glob('./siec/train/toxic/*')
|
||||
self.image = np.random.choice(test)
|
||||
elif self.content=='clothes':
|
||||
test = glob('./siec/train/flammable/*')
|
||||
self.image = np.random.choice(test)
|
||||
else:
|
||||
self.image='./fruit.png'
|
||||
print(self.image)
|
||||
self.category = category
|
||||
|
||||
|
||||
class Clothes(Cargo):
|
||||
def __init__(self, name, size, weight, fragility):
|
||||
|
@ -1,74 +0,0 @@
|
||||
digraph {
|
||||
root [label=root]
|
||||
Label_State [label=Label_State]
|
||||
no [label=no]
|
||||
Label_State -> no [label=""]
|
||||
Height [label=Height]
|
||||
no -> Height [label=""]
|
||||
no [label=no shape=box]
|
||||
Height -> no [label=medium]
|
||||
no [label=no shape=box]
|
||||
Height -> no [label=big]
|
||||
small [label=small]
|
||||
Height -> small [label=""]
|
||||
Width [label=Width]
|
||||
small -> Width [label=""]
|
||||
small [label=small]
|
||||
Width -> small [label=""]
|
||||
Depth [label=Depth]
|
||||
small -> Depth [label=""]
|
||||
no [label=no shape=box]
|
||||
Depth -> no [label=big]
|
||||
yes [label=yes shape=box]
|
||||
Depth -> yes [label=medium]
|
||||
no [label=no shape=box]
|
||||
Width -> no [label=big]
|
||||
medium [label=medium]
|
||||
Width -> medium [label=""]
|
||||
Depth [label=Depth]
|
||||
medium -> Depth [label=""]
|
||||
no [label=no shape=box]
|
||||
Depth -> no [label=big]
|
||||
yes [label=yes shape=box]
|
||||
Depth -> yes [label=medium]
|
||||
yes [label=yes shape=box]
|
||||
Depth -> yes [label=small]
|
||||
yes [label=yes]
|
||||
Label_State -> yes [label=""]
|
||||
Damage [label=Damage]
|
||||
yes -> Damage [label=""]
|
||||
yes [label=yes shape=box]
|
||||
Damage -> yes [label=no]
|
||||
yes [label=yes]
|
||||
Damage -> yes [label=""]
|
||||
Height [label=Height]
|
||||
yes -> Height [label=""]
|
||||
no [label=no shape=box]
|
||||
Height -> no [label=medium]
|
||||
no [label=no shape=box]
|
||||
Height -> no [label=big]
|
||||
small [label=small]
|
||||
Height -> small [label=""]
|
||||
Width [label=Width]
|
||||
small -> Width [label=""]
|
||||
no [label=no shape=box]
|
||||
Width -> no [label=big]
|
||||
small [label=small]
|
||||
Width -> small [label=""]
|
||||
Depth [label=Depth]
|
||||
small -> Depth [label=""]
|
||||
yes [label=yes shape=box]
|
||||
Depth -> yes [label=medium]
|
||||
no [label=no shape=box]
|
||||
Depth -> no [label=big]
|
||||
yes [label=yes shape=box]
|
||||
Depth -> yes [label=small]
|
||||
medium [label=medium]
|
||||
Width -> medium [label=""]
|
||||
Value [label=Value]
|
||||
medium -> Value [label=""]
|
||||
yes [label=yes shape=box]
|
||||
Value -> yes [label=cheap]
|
||||
no [label=no shape=box]
|
||||
Value -> no [label=expensive]
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
import torch.optim as optim
|
||||
from torch.utils.data import Dataset, DataLoader
|
||||
import torchvision
|
||||
import torchvision.transforms as transforms
|
||||
from torchvision.datasets import ImageFolder
|
||||
import timm
|
||||
|
||||
import matplotlib.pyplot as plt # For data viz
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import sys
|
||||
|
||||
class LabelDataset(Dataset):
|
||||
def __init__(self, dataDirectory,transform=None):
|
||||
self.data=ImageFolder(dataDirectory,transform=transform)
|
||||
def __len__(self):
|
||||
return len(self.data)
|
||||
def __getitem__(self, idx):
|
||||
return self.data[idx]
|
||||
|
||||
@property
|
||||
def classes(self):
|
||||
return self.data.classes
|
||||
|
||||
classname={v:k for k,v in ImageFolder('./train').class_to_idx.items()}
|
||||
|
||||
transform=transforms.Compose([
|
||||
transforms.Resize((128,128)),
|
||||
transforms.ToTensor(),
|
||||
])
|
||||
|
||||
dataset=LabelDataset('./train',transform)
|
||||
dataloader=DataLoader(dataset,batch_size=4, shuffle=True)
|
||||
valset=LabelDataset('./val',transform)
|
||||
valloader=DataLoader(valset,batch_size=4,shuffle=False)
|
||||
|
||||
for images,labels in dataloader:
|
||||
break
|
@ -1,114 +0,0 @@
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
import torch.optim as optim
|
||||
from torch.utils.data import Dataset, DataLoader
|
||||
import torchvision
|
||||
import torchvision.transforms as transforms
|
||||
from torchvision.datasets import ImageFolder
|
||||
import timm
|
||||
from PIL import Image
|
||||
|
||||
import matplotlib.pyplot as plt # For data viz
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import sys
|
||||
from siec import dataset
|
||||
from glob import glob
|
||||
|
||||
class LabelClassifier(nn.Module):
|
||||
def __init__(self,num_classes=3):
|
||||
super(LabelClassifier, self).__init__()
|
||||
self.model=timm.create_model('efficientnet_b0',pretrained=True)
|
||||
self.features = nn.Sequential(*list(self.model.children())[:-1])
|
||||
out_size=1280
|
||||
self.classifier=nn.Linear(out_size,num_classes)
|
||||
def forward(self,x):
|
||||
x=self.features(x)
|
||||
output=self.classifier(x)
|
||||
return output
|
||||
model=torch.load("./model")
|
||||
|
||||
criterion=nn.CrossEntropyLoss()
|
||||
optimizer=optim.Adam(model.parameters(),lr=0.0005)
|
||||
print(criterion(model(dataset.images),dataset.labels))
|
||||
|
||||
num_epochs=0
|
||||
trainLosses=[]
|
||||
valLosses=[]
|
||||
|
||||
device=torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
||||
model.to(device)
|
||||
|
||||
for epoch in range(num_epochs):
|
||||
model.train()
|
||||
runningLoss=0.0
|
||||
for images,labels in dataset.dataloader:
|
||||
images, labels=images.to(device), labels.to(device)
|
||||
optimizer.zero_grad()
|
||||
outputs=model(images)
|
||||
loss=criterion(outputs,labels)
|
||||
loss.backward()
|
||||
optimizer.step()
|
||||
runningLoss+=loss.item()*images.size(0)
|
||||
trainLoss=runningLoss/len(dataset.dataloader.dataset)
|
||||
trainLosses.append(trainLoss)
|
||||
|
||||
model.eval()
|
||||
runningLoss=0.0
|
||||
with torch.no_grad():
|
||||
for images, labels in dataset.valloader:
|
||||
images, labels = images.to(device), labels.to(device)
|
||||
outputs=model(images)
|
||||
loss=criterion(outputs,labels)
|
||||
runningLoss+=loss.item()*images.size(0)
|
||||
valLoss=runningLoss/len(dataset.valloader.dataset)
|
||||
valLosses.append(valLoss)
|
||||
print(f"Epoch {epoch + 1}/{num_epochs} - Train loss: {trainLoss}, Validation loss: {valLoss}")
|
||||
modell=torch.jit.script(model)
|
||||
modell.save('model.pt')
|
||||
|
||||
|
||||
def preprocess_image(image_path, transform):
|
||||
image = Image.open(image_path).convert("RGB")
|
||||
return image, transform(image).unsqueeze(0)
|
||||
|
||||
# Predict using the model
|
||||
def predict(model, image_tensor, device):
|
||||
model.eval()
|
||||
with torch.no_grad():
|
||||
image_tensor = image_tensor.to(device)
|
||||
outputs = model(image_tensor)
|
||||
probabilities = torch.nn.functional.softmax(outputs, dim=1)
|
||||
print(outputs)
|
||||
return probabilities.cpu().numpy().flatten()
|
||||
|
||||
# Visualization
|
||||
def visualize_predictions(original_image, probabilities, class_names):
|
||||
fig, axarr = plt.subplots(1, 2, figsize=(14, 7))
|
||||
axarr[0].imshow(original_image)
|
||||
axarr[0].axis("off")
|
||||
|
||||
# Display predictions
|
||||
axarr[1].barh(class_names, probabilities)
|
||||
axarr[1].set_xlabel("Probability")
|
||||
axarr[1].set_title("Class Predictions")
|
||||
axarr[1].set_xlim(0, 1)
|
||||
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
transform = transforms.Compose([
|
||||
transforms.Resize((128, 128)),
|
||||
transforms.ToTensor()
|
||||
])
|
||||
test_images = glob('./train/*/*')
|
||||
test_examples = np.random.choice(test_images, 10)
|
||||
for example in test_examples:
|
||||
model.eval()
|
||||
original_image, image_tensor = preprocess_image(example, transform)
|
||||
probabilities = predict(model, image_tensor, device)
|
||||
print(probabilities)
|
||||
|
||||
# Assuming dataset.classes gives the class names
|
||||
class_names = dataset.dataset.classes
|
||||
visualize_predictions(original_image, probabilities, class_names)
|
||||
model(image_tensor)
|
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 56 KiB |
Before Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 92 KiB |
Before Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 45 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 75 KiB |
Before Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 7.1 KiB |
Before Width: | Height: | Size: 7.3 KiB |
Before Width: | Height: | Size: 4.9 KiB |
Before Width: | Height: | Size: 9.2 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 9.2 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 7.4 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 8.7 KiB |
Before Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 8.4 KiB |
Before Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 7.2 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 8.1 KiB |
Before Width: | Height: | Size: 9.3 KiB |
Before Width: | Height: | Size: 7.7 KiB |
Before Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 7.2 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 7.7 KiB |
Before Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 8.0 KiB |
Before Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 8.5 KiB |
Before Width: | Height: | Size: 8.1 KiB |
Before Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 9.0 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 13 KiB |