Comments (4)
Hello @nemeziz69, thank you for your interest in speedster! Which data loader are you using? If it's a custom one, can you provide the implementation of the __getitem__()
method so that I can check?
from nebuly.
Hello @nemeziz69, thank you for your interest in speedster! Which data loader are you using? If it's a custom one, can you provide the implementation of the
__getitem__()
method so that I can check?
Hi @valeriosofi ,
DataLoader is not custom, it's directly from torch.
from torch.utils.data import DataLoader, Dataset
input_data = DataLoader(dataset, batch_size=1, num_workers=1, pin_memory=True)
However, my dataset is custom. Here the full implementation:
import cv2
from tqdm import tqdm
from torch.utils.data import DataLoader, Dataset
class SampleDataset(Dataset):
def __init__(self, image_tensor_array):
self.data = torch.as_tensor(image_tensor_array)
def __getitem__(self, index):
x = self.data[index]
return x
def __len__(self):
return len(self.data)
def convert_dataset_to_crop_and_tensor(path, crop_x=None, crop_y=None, crop_h=None):
# Unpack parameter
if crop_x is not None and crop_y is not None and crop_h is not None:
crop_image = True
else:
crop_image = False
image_files = glob(f"{path}/*/*.jpg")
img_tensor_plist = []
for img in tqdm(image_files, desc="Converting"):
each_img = cv2.cvtColor(cv2.imread(img), cv2.COLOR_BGR2RGB)
if crop_image:
crop1 = each_img[crop_y:crop_y + crop_h, crop_x:crop_x + crop_h]
crop2 = each_img[crop_y:crop_y + crop_h, crop_x + crop_h:crop_x + crop_h * 2]
crop3 = each_img[crop_y:crop_y + crop_h, crop_x + crop_h * 2:crop_x + crop_h * 3]
img_list = [crop1, crop2, crop3]
else:
img_list = [each_img]
for imgcc in img_list:
convert_tensor = transforms.ToTensor()
image_tensor = convert_tensor(imgcc)
rescale_img = transforms.Resize(size=(608, 608))
resized_img = rescale_img(image_tensor)
img_tensor_plist.append(resized_img.numpy())
img_tensor_arr = torch.as_tensor(img_tensor_plist)
return img_tensor_arr
if __name__ == "__main__":
img_tensor_array = convert_dataset_to_crop_and_tensor(SAMPLE_DATASET_PATH, crop_x=0, crop_y=100, crop_h=1365)
dataset = SampleDataset(img_tensor_array)
input_data = DataLoader(dataset, batch_size=1, num_workers=1, pin_memory=True)
from nebuly.
Hi @nemeziz69, I tried with your code and unfortunately I can't reproduce your error. I've performed a few minor changes to run the code on my local env, at the end the dataloader outputs tensors of shape torch.Size([1, 3, 608, 608])
and speedster correctly processes the dataloader, can you check that you are passeng the dataloader correctly to speedster? Please also check that you are using the latest version, I'm using speedster==0.3.0
.
from glob import glob
import cv2
import torchvision.models as models
from speedster import optimize_model, save_model
from torch.utils.data import DataLoader, Dataset
from torchvision import transforms
from tqdm import tqdm
class SampleDataset(Dataset):
def __init__(self, image_tensor_array):
self.data = image_tensor_array
def __getitem__(self, index):
x = self.data[index]
return x
def __len__(self):
return len(self.data)
def convert_dataset_to_crop_and_tensor(path, crop_x=None, crop_y=None, crop_h=None):
# Unpack parameter
if crop_x is not None and crop_y is not None and crop_h is not None:
crop_image = True
else:
crop_image = False
image_files = glob(f"{path}/*.png")
img_tensor_plist = []
for img in tqdm(image_files, desc="Converting"):
each_img = cv2.cvtColor(cv2.imread(img), cv2.COLOR_BGR2RGB)
# Resize image to 4000x4000 to make sure that my images are not too small for the crop part
rescale_img = cv2.resize(each_img, (4000, 4000))
if crop_image:
crop1 = rescale_img[crop_y:crop_y + crop_h, crop_x:crop_x + crop_h]
crop2 = rescale_img[crop_y:crop_y + crop_h, crop_x + crop_h:crop_x + crop_h * 2]
crop3 = rescale_img[crop_y:crop_y + crop_h, crop_x + crop_h * 2:crop_x + crop_h * 3]
img_list = [crop1, crop2, crop3]
else:
img_list = [rescale_img]
for imgcc in img_list:
convert_tensor = transforms.ToTensor()
image_tensor = convert_tensor(imgcc)
rescale_img = transforms.Resize(size=(608, 608))
image_tensor = rescale_img(image_tensor)
img_tensor_plist.append(image_tensor)
return img_tensor_plist
if __name__ == "__main__":
img_tensor_array = convert_dataset_to_crop_and_tensor("images", crop_x=0, crop_y=100, crop_h=1365)
dataset = SampleDataset(img_tensor_array)
input_data = DataLoader(dataset, batch_size=1, num_workers=1, pin_memory=True)
# 1 Provide input model and data (we support PyTorch Dataloaders and custom input, see the docs to learn more)
model = models.resnet50()
# 2 Run Speedster optimization
optimized_model = optimize_model(
model,
input_data=input_data,
optimization_time="constrained",
metric_drop_ths=0.05
)
# 3 Save the optimized model
save_model(optimized_model, "model_save_path")
from nebuly.
Hi @valeriosofi, I'm confirm my speedster version is speedster==0.3.0
, and my dataloaders output shape is torch.Size([1, 3, 608, 608])
.
However, when I used the same model like yours which is models.resnet50()
, the PytorchBackendCompiler run perfectly without any WARNING
message.
So, I assume there's something wrong in my model input. FYI, I used custom pretrained model which is training output from this blog.
from nebuly.
Related Issues (20)
- [chatllama]Do I need to split the llama model manully? HOT 2
- [Chatllama] facebook/opt-350m is missing in rlhf/model_list.py HOT 2
- module not found:chatllama.rlhf.dataset HOT 1
- Support for torch 2.0 HOT 1
- Issues with accelerate and deepspeed training HOT 4
- [chatllama]How models enable inference HOT 1
- [Chatllama] what's supposed to be in the Actor checkpoint dir? HOT 3
- [chatllama]Puzzled about the update of the critic model
- yolov8 + nebuly | AttributeError: type object 'DummyClass' has no attribute 'models' HOT 10
- Evaluating accuracy of only the reward model
- [speedster] _dl_check_map_versions assertion error with optimize_model and ONNX compilers HOT 3
- torch2.0 support on speedster HOT 2
- Yolov8-Pose Model
- [ Speedster] With Hugging Face notebook code on nebulydocker/nebullvm container: RuntimeError: Expected all tensors to be on the same device HOT 5
- How to generate and perform inference for an ONNX model HOT 2
- Forward Forward Algorithm Questions HOT 2
- [Speedster] TensorRt OSError: [WinError 127] The specified procedure could not be found
- [Speedster] optimize_model took 10 hours, and it's not over yet
- nebullvm LICENSE and commercial use?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nebuly.