Semantic segmentation labeling - deep-learning

I'm trynna make a scratch code of Semantic segmentation through U-Net. I'll use Cityscapes Dataset. I'm trying to make a dictionary(python) composed of the key(car, train, human, etc) and the value(rgb info). How can I match the dictionary with my ground_truth data?
example of labeling dictionary is like below
color_map = {
'0': [0, 0, 0], # unlabelled
'1': [128, 64, 128], # road
'2': [244, 35, 232], # sidewalk
'3': [70, 70, 70], # building
'4': [102, 102, 156], # wall
'5': [190, 153, 153], # fence
'6': [153, 153, 153], # pole
'7': [250,170, 30], # traffic_light
'8': [220, 220, 0], # traffic_sign
'9': [107, 142, 35], # vegetation
'10': [152, 251, 152], # terrain
'11': [0, 130, 180], # sky
'12': [220, 20, 60], # person
'13': [255, 0, 0], # rider
'14': [0, 0, 142], # car
'15': [0, 0, 70], # truck
'16': [0, 60, 100], # bus
'17': [0, 80, 100], # train
'18': [0, 0, 230], # motorcycle
'19': [119, 11, 32] # bicycle
}

Related

Hyperparameter Tuning with Wandb Sweep for custom parameters

I'm trying to tune the hyperparameters using the Stable-Baseline-3 Library for the network architecture.
My configuration file is:
program: main.py
method: bayes
name: sweep
metric:
goal: minimize
name: train/loss
parameters:
batch_size:
values: [16, 32, 64, 128, 256, 512, 1024]
epochs:
values: [20, 50, 100, 200, 250, 300]
lr:
max: 0.1
min: 0.000001
But if I try to add to the parameters:
policy_kwargs:
net_arch:
pi:
values: [[ 128, 128 ],[ 256, 256 ],[ 512, 512 ]]
vf:
values: [[ 128, 128 ],[ 256, 256 ],[ 512, 512 ]]
I got the following error:
wandb.errors.CommError: Invalid sweep config: invalid hyperparameter configuration: policy_kwargs
Is it possible to use wandb sweep with Stable-Baseline-3 for the network architecture?
You are trying to create a nested config. Please refer to this documentation here.
Your configuration should be:
program: main.py
method: bayes
name: sweep
metric:
goal: minimize
name: train/loss
parameters:
batch_size:
values: [16, 32, 64, 128, 256, 512, 1024]
epochs:
values: [20, 50, 100, 200, 250, 300]
lr:
max: 0.1
min: 0.000001
policy_kwargs:
parameters:
net_arch:
parameters:
pi:
values: [[ 128, 128 ],[ 256, 256 ],[ 512, 512 ]]
vf:
values: [[ 128, 128 ],[ 256, 256 ],[ 512, 512 ]]

Django combine two json objects to form a new array

I have two json objects as follow
Id:1
{"points":[{"x":109,"y":286,"r":1,"color":"black"},{"x":108,"y":285,"r":1,"color":"black"},{"x":106,"y":282,"r":1,"color":"black"},{"x":103,"y":276,"r":1,"color":"black"},],"lines":[{"x1":109,"y1":286,"x2":108,"y2":285,"strokeWidth":"2","strokeColor":"black"},{"x1":108,"y1":285,"x2":106,"y2":282,"strokeWidth":"2","strokeColor":"black"},{"x1":106,"y1":282,"x2":103,"y2":276,"strokeWidth":"2","strokeColor":"black"}]}
Id-2
{"points":[{"x":524,"y":343,"r":1,"color":"black"},{"x":523,"y":342,"r":1,"color":"black"},{"x":521,"y":339,"r":1,"color":"black"},{"x":520,"y":334,"r":1,"color":"black"},{"x":514,"y":319,"r":1,"color":"black"}],"lines":[{"x1":524,"y1":343,"x2":523,"y2":342,"strokeWidth":"2","strokeColor":"black"},{"x1":523,"y1":342,"x2":521,"y2":339,"strokeWidth":"2","strokeColor":"black"},{"x1":521,"y1":339,"x2":520,"y2":334,"strokeWidth":"2","strokeColor":"black"},{"x1":520,"y1":334,"x2":514,"y2":319,"strokeWidth":"2","strokeColor":"black"}]}
I am trying to merge these two data onto a canvas
I am able to retrieve a single file but combining them i am not able to do
def loadDrawing(request):
""" Function to load the drawing with drawingID if it exists."""
try:
# Getting JSON object string of saved drawing.
drawingJSONData = Drawing.objects.get(id = 1).drawingJSONText
# drawingJSONData1 = Drawing.objects.get(id=1).drawingJSONText
# drawingJSONData2 = Drawing.objects.get(id=2).drawingJSONText
# Seding context with appropriate information
context = {
"loadIntoJavascript" : True,
"JSONData" : drawingJSONData
}
# Editing response headers and returning the same
response = modifiedResponseHeaders(render(request, 'MainCanvas/index.html', context))
return response
My model in django
class Drawing(models.Model):
drawingJSONText = models.TextField(null = True)
My .js file to load the drawing and parsing it from server to JSON object and pushing the loaded points into an array
// Checking if the drawing to be loaded exists
if (document.getElementById('JSONLoadData') != null)
{
// Parsing the loaded drawing from server to a JSON Object
var loadedData = JSON.parse(JSONLoadData.value)
// Iterating through all the points in the loaded drawing
for(let i = 0; i < loadedData['points'].length; i++)
{
// Saving the point and drawing the same in the svg canvas
const point = svg.append('circle')
.attr('cx', loadedData['points'][i]['x'])
.attr('cy', loadedData['points'][i]['y'])
.attr('r', loadedData['points'][i]['r'])
.style('fill', loadedData['points'][i]['color']);
// Pushing the point inside points array
points.push(point);
}
// Iterating through all the lines in the loaded drawing
for(let i = 0; i < loadedData['lines'].length; i++)
{
// Saving the line and drawing the same in the svg canvas
const line = svg.append('line')
.attr('x1', loadedData['lines'][i]['x1'])
.attr('y1', loadedData['lines'][i]['y1'])
.attr('x2', loadedData['lines'][i]['x2'])
.attr('y2', loadedData['lines'][i]['y2'])
.attr('stroke-width', loadedData['lines'][i]['strokeWidth'])
.style('stroke', loadedData['lines'][i]['strokeColor']);
// Pushing the line inside lines array
lines.push(line);
}
}
});
Edited :
If my model is as follows
class Drawing(models.Model):
drawingJSONText = models.TextField(null=True)
project = models.CharField(max_length=250)
How can i filter data based on project
Lets say i have three datasets
1st one contains project = a
2nd one contains project = b
3rd one contains project = a
4th one contains project = a
How can i add datapoints like above by filtering data Drawing.objects.filter(project=a)
then based on the queryset i have three data points and corresponding data are plotted on canvas as above
I'm not entirely sure this is what you want, but are you trying to combine id-1 and id-2? If I think I understand what you are trying to do, will using the + operator work for you in this case?
drawingJSONData1 = json.loads(Drawing.objects.get(id=1).drawingJSONText)
drawingJSONData2 = json.loads(Drawing.objects.get(id=1).drawingJSONText)
drawingJSONData = dict()
drawingJSONData["points"] = drawingJSONData1["points"]+drawingJSONData1["points"]
drawingJSONData["lines"] = drawingJSONData2["lines"]+drawingJSONData2["lines"]
With your example above, you'd end up with:
{'points': [{'x': 109, 'y': 286, 'r': 1, 'color': 'black'},
{'x': 108, 'y': 285, 'r': 1, 'color': 'black'},
{'x': 106, 'y': 282, 'r': 1, 'color': 'black'},
{'x': 103, 'y': 276, 'r': 1, 'color': 'black'},
{'x': 524, 'y': 343, 'r': 1, 'color': 'black'},
{'x': 523, 'y': 342, 'r': 1, 'color': 'black'},
{'x': 521, 'y': 339, 'r': 1, 'color': 'black'},
{'x': 520, 'y': 334, 'r': 1, 'color': 'black'},
{'x': 514, 'y': 319, 'r': 1, 'color': 'black'}],
'lines': [{'x1': 109,
'y1': 286,
'x2': 108,
'y2': 285,
'strokeWidth': '2',
'strokeColor': 'black'},
{'x1': 108,
'y1': 285,
'x2': 106,
'y2': 282,
'strokeWidth': '2',
'strokeColor': 'black'},
{'x1': 106,
'y1': 282,
'x2': 103,
'y2': 276,
'strokeWidth': '2',
'strokeColor': 'black'},
{'x1': 524,
'y1': 343,
'x2': 523,
'y2': 342,
'strokeWidth': '2',
'strokeColor': 'black'},
{'x1': 523,
'y1': 342,
'x2': 521,
'y2': 339,
'strokeWidth': '2',
'strokeColor': 'black'},
{'x1': 521,
'y1': 339,
'x2': 520,
'y2': 334,
'strokeWidth': '2',
'strokeColor': 'black'},
{'x1': 520,
'y1': 334,
'x2': 514,
'y2': 319,
'strokeWidth': '2',
'strokeColor': 'black'}]}
EDIT: added the gets wrapped in json.loads to convert string to Python object as I don't know what kind of field that is and given the error being seen.

Strange JSON keyerror python 3

I have been getting some strange key errors when trying to load a value after a few game ticks in my case, there is no modification going on cause most of it gets loaded from class internally at initiation, here is an quick example of the error im getting when trying to access.
also link to source is here, im pretty new and just have been coding for aint to long so please no judgement.
{'calleas': {'player': {'x': 5, 'y': 5, 'id': 'npc_1'}, '1': {'x': 6, 'y': 8, 'id': 'npc_2'}, '2': {'x': 5, 'y': 8, 'id': 'npc_3'}}, 'calleas_forest': {'player': {'x': 55, 'y': 5, 'id': 'npc_1'}}}
{'calleas': {'0': {'object_id': 7, 'x': 0, 'y': 5, 'walkable': True, 'gamestate': 'callaes_forest'}, '1': {'object_id': 7, 'x': 0, 'y': 4, 'walkable': True, 'gamestate': 'callaes_forest'}}, 'callaes_forest': {'0': {'object_id': 7, 'x': 56, 'y': 5, 'walkable': True, 'gamestate': 'callaes_forest'}, '1': {'object_id': 7, 'x': 56, 'y': 4, 'walkable': True, 'gamestate': 'callaes_forest'}}}
None
Traceback (most recent call last):
File "C:/Users/Jannick/PycharmProjects/NewRemake/Game.py", line 39, in <module>
g.start_game()
File "C:/Users/Jannick/PycharmProjects/NewRemake/Game.py", line 33, in start_game
self.update()
File "C:\Users\Jannick\PycharmProjects\NewRemake\GameHandler.py", line 106, in update
self.entity_handler.update()
File "C:\Users\Jannick\PycharmProjects\NewRemake\Entity\EntityHandler.py", line 21, in update
self.game.player.update()
File "C:\Users\Jannick\PycharmProjects\NewRemake\Entity\Entity.py", line 35, in update
self.move(x=1)
File "C:\Users\Jannick\PycharmProjects\NewRemake\Entity\Player.py", line 47, in move
self.game.map_handler.load(self.game.map_handler.new_map_name(dest_x, dest_y))
File "C:\Users\Jannick\PycharmProjects\NewRemake\World\MapBuilder.py", line 26, in load
self.get_map_configuration(map_config)
File "C:\Users\Jannick\PycharmProjects\NewRemake\World\MapBuilder.py", line 46, in get_map_configuration
"entitys": self.all_map_entitys[map_config]
KeyError: 'callaes_forest'
{'calleas': {'player': {'x': 5, 'y': 5, 'id': 'npc_1'}, '1': {'x': 6, 'y': 8, 'id': 'npc_2'}, '2': {'x': 5, 'y': 8, 'id': 'npc_3'}}, 'calleas_forest': {'player': {'x': 55, 'y': 5, 'id': 'npc_1'}}}

Scikit-Learn Encoding Categorical Features - ValueError: setting an array element with a sequence

I am trying to use sklearn.preprocessing.OneHotEncoder to binarize my categorical variables before use in some regression methods such as OLS, the Lasso etc.
I have a nested list like so:
l = [[0, 0, 0], [0, 1, 1], [1, 2, 2], [0, 3, 2], [1, 4, 0], [0, 5, 2], [2, 2, 2], [0, 6, 2], [1, 7, 2], [0, 8, 3], [3, 4, 2], [0, 8, 4], [0, 9, 2], [1, 7, 1], [0, 10, 2], [0, 2, 5], [1, 11, 2], [1, 2, 3], [4, 12, 2], [1, 4, 2], [0, 13, 2], [0, 14, 2], [0, 15, 2], [0, 16, 0], [0, 17, 6], [5, 17, 2], [4, 17, 2], [0, 17, 3], [0, 2, 6], [0, 8, 6], [4, 2, 2], [4, 4, 2], [5, 15, 3], [0, 2, 3], [0, 7, 2], [1, 15, 2], [0, 17, 2], [0, 8, 2], [0, 2, 2], [4, 16, 2], [0, 1, 2], [5, 15, 2], [4, 8, 0], [0, 18, 3], [3, 11, 2], [6, 7, 2], [0, 8], [0, 19, 2], [1, 1, 2], [0, 7, 0], [0, 1, 0], [0, 4, 2], [0, 15, 3], [7, 8, 2], [1, 8, 0], [1, 16, 2], [0, 20, 2], [1, 8], [1, 8, 2], [0, 11, 1], [1, 21, 2], [4, 1, 2], [5, 1, 2], [2, 1, 2], [0, 22, 2], [8, 8, 2], [1, 8, 3], [1, 17, 2], [0, 8, 7], [0, 0, 2], [7, 7, 2], [2, 2, 8], [9, 8, 2], [5, 8, 2], [4, 8, 2], [0, 4, 3], [0, 23, 0], [0, 24, 2], [0, 2, 0], [3, 1, 2], [0, 25, 2], [0, 2, 9], [0, 11, 2], [1, 12, 2], [1, 26, 3], [0, 23, 2], [0, 27, 3], [3, 8, 2], [6, 8, 2], [6, 27, 2], [0, 16, 2], [0, 28, 2], [0, 29, 2], [0, 8, 0], [0, 8, 10], [0, 27, 2], [4, 7, 2], [0, 21, 2], [6, 11, 2], [0, 30, 2], [2, 8, 2], [0, 23, 3]]
from sklearn import preprocessing
enc = preprocessing.OneHotEncoder()
enc.fit(l)
However, I am running into the error:
ValueError: setting an array element with a sequence
Here is the most telling callback as far as I can see:
C:\Program Files\Anaconda\lib\site-packages\numpy\core\numeric.pyc in asarray(a, dtype, order)
458
459 """
--> 460 return array(a, dtype, copy=False, order=order)
461
462 def asanyarray(a, dtype=None, order=None):
To try and solve this problem I have attempted to convert my list to a matrix and array in numpy but have had no luck.
In addition, I have made sure that each value in each of the nested lists is an integer. I have also tried converting them to floats, again with no success.
Any help would be wonderful. Thanks.

How to set font size of 'open file tabs'?

I added "font.size": 15.0 to the tab_label class in Default.sublime-theme.
{
"class": "tab_label",
"fg": [0, 0, 0, 255],
"shadow_color": [255, 255, 255, 80],
"shadow_offset": [0, 1],
"font.size": 15.0
}
The font size did change, but the lower parts of the file names somehow 'get cut'.
What should I do?