This commit is contained in:
koncho1 2024-06-17 04:58:21 +02:00
parent ecc3534227
commit 3768d3a307
968 changed files with 742 additions and 454 deletions

11
ai-wozek/.idea/aws.xml Normal file
View File

@ -0,0 +1,11 @@
<?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>

7
ai-wozek/.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?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) (2)" project-jdk-type="Python SDK" />
</project>

View File

@ -1,18 +1,24 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="wozek" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true"> <configuration default="false" name="wozek" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="wozek" /> <module name="wozek" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" /> <option name="PARENT_ENVS" value="true" />
<envs> <envs>
<env name="PYTHONUNBUFFERED" value="1" /> <env name="PYTHONUNBUFFERED" value="1" />
</envs> </envs>
<option name="SDK_HOME" value="" /> <option name="SDK_HOME" value="" />
<option name="SDK_NAME" value="Python 3.10" /> <option name="SDK_NAME" value="Python 3.11 (ai-wozek) (2)" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" /> <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="false" /> <option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" /> <option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" /> <option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" /> <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="SCRIPT_NAME" value="$PROJECT_DIR$/wozek.py" />
<option name="PARAMETERS" value="" /> <option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" /> <option name="SHOW_COMMAND_LINE" value="false" />

View File

@ -1,7 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4"> <module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.11 (ai-wozek) (2)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

View File

@ -0,0 +1 @@
,DESKTOP-REF7T1M/abc,DESKTOP-REF7T1M,16.06.2024 22:58,file:///C:/Users/abc/AppData/Roaming/LibreOffice/4;

0
ai-wozek/cargo.py Normal file
View File

View File

@ -1,12 +1,31 @@
import random
from glob import glob
import numpy as np
class Cargo: class Cargo:
def __init__(self, name, category, size, weight): def __init__(self, height,width,depth,weight,damage,label_state,content,value,position):
self.name = name self.height=height
self.size = size self.width=width
self.weight = weight self.depth=depth
self.category = category 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)
class Clothes(Cargo): class Clothes(Cargo):
def __init__(self, name, size, weight, fragility): def __init__(self, name, size, weight, fragility):

Binary file not shown.

Binary file not shown.

Binary file not shown.

40
ai-wozek/siec/dataset.py Normal file
View File

@ -0,0 +1,40 @@
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

BIN
ai-wozek/siec/model Normal file

Binary file not shown.

BIN
ai-wozek/siec/model.pt Normal file

Binary file not shown.

114
ai-wozek/siec/model.py Normal file
View File

@ -0,0 +1,114 @@
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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Some files were not shown because too many files have changed in this diff Show More