Coder Social home page Coder Social logo

pedestrian-segmentation's Introduction

pedestrian-segmentation's People

Contributors

aditya239233 avatar

Watchers

 avatar

pedestrian-segmentation's Issues

why cant i use this code for predicting images other than dataset images

In predictsegmentation.py
when i upload the image from the Penn-Fudan Dataset ,I am getting segmentation correctly like below

Screenshot 2021-03-19 164244

when i run the code for an image which i have dowloaded from the net, the segmentation is not happening ,it is showing the blank image like below

Screenshot 2021-03-19 163704
The code is only working for the images in the Penn-Fudan Dataset, but when i run the code on images other than the Penn-Fudan Dataset it is not working.
What is the main reason for it?

ForkingPickler(file, protocol).dump(obj) BrokenPipeError: [Errno 32] Broken pipe

from dataset import Dataset
from model import model
from helper import add_pallet, collate_fn, get_transform

import torch
from PIL import Image
from matplotlib import pyplot as plt
from engine import train_one_epoch, evaluate

#%%
image = Image.open('../data/PNGImages/PennPed00035.png')
mask = Image.open('../data/PedMasks/PennPed00035_mask.png')
_, axs = plt.subplots(1, 2, figsize=(12, 12))
axs = axs.flatten()
imgs = [image, mask]
for img, ax in zip(imgs, axs):
ax.imshow(img)
plt.show()

#%%
dataset_train = Dataset('../data/', get_transform(train=True))
dataset_test = Dataset('../data/', get_transform(train=False))

print(dataset_train[0])

#%%
torch.manual_seed(1)
indices = torch.randperm(len(dataset_train)).tolist()
dataset_train = torch.utils.data.Subset(dataset_train, indices[:-50])
dataset_test = torch.utils.data.Subset(dataset_test, indices[-50:])

define training and validation data loaders

data_loader_train = torch.utils.data.DataLoader(
dataset_train, batch_size=2, shuffle=True, num_workers=4,
collate_fn=collate_fn)

data_loader_test = torch.utils.data.DataLoader(
dataset_test, batch_size=1, shuffle=False, num_workers=4,
collate_fn=collate_fn)

#%%
device = torch.device('cpu')

our dataset has two classes only - background and person

num_classes = 2

model = model(num_classes)

model.to(device)

params = [p for p in model.parameters() if p.requires_grad]
optimizer = torch.optim.SGD(params, lr=0.005,
momentum=0.9, weight_decay=0.0005)
lr_scheduler = torch.optim.lr_scheduler.StepLR(optimizer,
step_size=3,
gamma=0.1)

#%%
num_epochs = 10

for epoch in range(num_epochs):
train_one_epoch(model, optimizer, data_loader_train, device, epoch, print_freq=10)
lr_scheduler.step()

evaluate(model, data_loader_test, device=device)

torch.save(model.state_dict(), "../model/model.pth")

#%%
img, _ = dataset_test[0]

model.eval()
with torch.no_grad():
prediction = model([img.to(device)])
print(prediction)
#%%
image = Image.fromarray(img.mul(255).permute(1, 2, 0).byte().numpy())
mask = Image.fromarray(prediction[0]['masks'][0, 0].mul(255).byte().cpu().numpy())
_, axs = plt.subplots(1, 2, figsize=(12, 12))
axs = axs.flatten()
imgs = [image, mask]
for img, ax in zip(imgs, axs):
ax.imshow(img)
plt.show()

When I run this code i am getting BrokenPipeError
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 114, in _main
prepare(preparation_data)
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 225, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
run_name="mp_main")
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\MINI PROJECT\Pedestrian-Segmentation-main\src\PedestrianDetection.py", line 63, in
train_one_epoch(model, optimizer, data_loader_train, device, epoch, print_freq=10)
File "D:\MINI PROJECT\Pedestrian-Segmentation-main\src\engine.py", line 26, in train_one_epoch
for images, targets in metric_logger.log_every(data_loader, print_freq, header):
File "D:\MINI PROJECT\Pedestrian-Segmentation-main\src\utils.py", line 201, in log_every
for obj in iterable:
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\utils\data\dataloader.py", line 355, in iter
return self._get_iterator()
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\utils\data\dataloader.py", line 301, in _get_iterator
return _MultiProcessingDataLoaderIter(self)
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\utils\data\dataloader.py", line 914, in init
w.start()
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\multiprocessing\process.py", line 112, in start
self._popen = self._Popen(self)
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\multiprocessing\context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\multiprocessing\popen_spawn_win32.py", line 46, in init
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 143, in get_preparation_data
_check_not_importing_main()
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\multiprocessing\spawn.py", line 136, in _check_not_importing_main
is not going to be frozen to produce an executable.''')
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

Traceback (most recent call last):
File "D:\MINI PROJECT\Pedestrian-Segmentation-main\src\PedestrianDetection.py", line 63, in
train_one_epoch(model, optimizer, data_loader_train, device, epoch, print_freq=10)
File "D:\MINI PROJECT\Pedestrian-Segmentation-main\src\engine.py", line 26, in train_one_epoch
for images, targets in metric_logger.log_every(data_loader, print_freq, header):
File "D:\MINI PROJECT\Pedestrian-Segmentation-main\src\utils.py", line 201, in log_every
for obj in iterable:
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\utils\data\dataloader.py", line 355, in iter
return self._get_iterator()
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\utils\data\dataloader.py", line 301, in _get_iterator
return _MultiProcessingDataLoaderIter(self)
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\utils\data\dataloader.py", line 914, in init
w.start()
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\multiprocessing\process.py", line 112, in start
self._popen = self._Popen(self)
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\multiprocessing\context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\multiprocessing\popen_spawn_win32.py", line 89, in init
reduction.dump(process_obj, to_child)
File "C:\Users\Prem\AppData\Local\Programs\Python\Python37\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
BrokenPipeError: [Errno 32] Broken pipe

I didn't understand why i am getting this error
Can you please explain this? Thank u

from vision.references.detection import utils ModuleNotFoundError: No module named 'vision'

import torchvision
from vision.references.detection import utils
import vision.references.detection.transforms as T

def get_transform(train):
# data augmentation
transforms = []
transforms.append(T.ToTensor())

if train:
    transforms.append(T.RandomHorizontalFlip(0.5))

return T.Compose(transforms)

def add_pallet(mask):
mask.putpalette([
0, 0, 0, # black background
255, 0, 0, # index 1 is red
255, 255, 0, # index 2 is yellow
255, 153, 0, # index 3 is orange
])
return mask

def collate_fn(batch):
return tuple(zip(*batch))

error i am getting is
Traceback (most recent call last):
File "D:\MINI PROJECT\Pedestrian-Segmentation-main\src\helper.py", line 2, in
from vision.references.detection import utils
ModuleNotFoundError: No module named 'vision'

I cannot use this code for predicting images other than dataset images

Yes, For both the outputs, I am reading the file in the exact same way.
The code is working perfectly for all images in the Penn-Fudan Dataset .
when I run the code for an image which I have dowloaded from the net, the segmentation is not happening ,it is showing the blank image like below

Screenshot 2021-03-19 163704

The code is only working for the images in the Penn-Fudan Dataset, but when I run the code on images other than the Penn-Fudan Dataset it is not working.
What is the main reason for it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.