Implementing Deep Learning architecture with a given dataset - machine-learning

I am quite new in caffe and in deep learning. I am just trying to implement deep learning architecture.
This is the architecture that i am trying to implement . The architecture and Parse27k dataset was created and constructed by Computer Vision Group at the Visual Computing Institute, RWTH Aachen University .
Below you can see my models that i need to improve :
Train_val.prototxt
name: "Parse27"
layer {
name: "data"
type: "HDF5Data"
top: "crops"
top: "labels"
include {
phase: TRAIN
}
hdf5_data_param {
source: "/home/nail/caffe/caffe/examples/hdf5_classification/data/train.txt"
batch_size: 256
}
}
layer {
name: "data"
type: "HDF5Data"
top: "crops"
top: "labels"
include {
phase: TEST
}
hdf5_data_param {
source: "/home/nail/caffe/caffe/examples/hdf5_classification/data/test.txt"
batch_size: 256
}
}
layer {
name: "conv1"
type: "Convolution"
bottom: "crops"
top: "conv1"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 96
kernel_size: 11
stride: 4
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "relu1"
type: "ReLU"
bottom: "conv1"
top: "conv1"
}
layer {
name: "pool1"
type: "Pooling"
bottom: "conv1"
top: "pool1"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
}
}
layer {
name: "norm1"
type: "LRN"
bottom: "pool1"
top: "norm1"
lrn_param {
local_size: 5
alpha: 0.0001
beta: 0.75
}
}
layer {
name: "conv2"
type: "Convolution"
bottom: "norm1"
top: "conv2"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 256
pad: 2
kernel_size: 5
group: 2
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 1
}
}
}
layer {
name: "relu2"
type: "ReLU"
bottom: "conv2"
top: "conv2"
}
layer {
name: "pool2"
type: "Pooling"
bottom: "conv2"
top: "pool2"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
}
}
layer {
name: "norm2"
type: "LRN"
bottom: "pool2"
top: "norm2"
lrn_param {
local_size: 5
alpha: 0.0001
beta: 0.75
}
}
layer {
name: "conv3"
type: "Convolution"
bottom: "norm2"
top: "conv3"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 384
pad: 1
kernel_size: 3
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "relu3"
type: "ReLU"
bottom: "conv3"
top: "conv3"
}
layer {
name: "conv4"
type: "Convolution"
bottom: "conv3"
top: "conv4"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 384
pad: 1
kernel_size: 3
group: 2
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 1
}
}
}
layer {
name: "relu4"
type: "ReLU"
bottom: "conv4"
top: "conv4"
}
layer {
name: "conv5"
type: "Convolution"
bottom: "conv4"
top: "conv5"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 256
pad: 1
kernel_size: 3
group: 2
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 1
}
}
}
layer {
name: "relu5"
type: "ReLU"
bottom: "conv5"
top: "conv5"
}
layer {
name: "pool5"
type: "Pooling"
bottom: "conv5"
top: "pool5"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
}
}
layer {
name: "fc6"
type: "InnerProduct"
bottom: "pool5"
top: "fc6"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
inner_product_param {
num_output: 4096
weight_filler {
type: "gaussian"
std: 0.005
}
bias_filler {
type: "constant"
value: 1
}
}
}
layer {
name: "relu6"
type: "ReLU"
bottom: "fc6"
top: "fc6"
}
layer {
name: "drop6"
type: "Dropout"
bottom: "fc6"
top: "fc6"
dropout_param {
dropout_ratio: 0.5
}
}
layer {
name: "fc7"
type: "InnerProduct"
bottom: "fc6"
top: "fc7"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
inner_product_param {
num_output: 4096
weight_filler {
type: "gaussian"
std: 0.005
}
bias_filler {
type: "constant"
value: 1
}
}
}
layer {
name: "relu7"
type: "ReLU"
bottom: "fc7"
top: "fc7"
}
layer {
name: "drop7"
type: "Dropout"
bottom: "fc7"
top: "fc7"
dropout_param {
dropout_ratio: 0.5
}
}
layer {
name: "fc8"
type: "InnerProduct"
bottom: "fc7"
top: "fc8"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
inner_product_param {
num_output: 1000
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "accuracy"
type: "Accuracy"
bottom: "fc8"
bottom: "labels"
top: "accuracy"
include {
phase: TEST
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "fc8"
bottom: "labels"
top: "loss"
}
Solver.prototxt
net: "models/Parse27/train_val.prototxt"
test_iter: 1000
test_interval: 1000
base_lr: 0.01
lr_policy: "step"
gamma: 0.1
stepsize: 100000
display: 20
max_iter: 450000
momentum: 0.9
weight_decay: 0.0005
snapshot: 10000
snapshot_prefix: "models/Parse27/Parse27_train"
solver_mode: GPU
I have 2 main hardships in implementing this architecture.
As seen above, my model does not include custom-loss layer. My model is almost caffeNet architecture. But i should replace my last layer which is inside the red box with custom loss layer (green box).
My train dataset has following structure.
crops Dataset {27482, 3, 128, 192}
labels Dataset {27482, 12}
mean Dataset {3, 128, 192}
pids Dataset {27482}
As seen here number of rows(examples) in crops and in labels are same 27482. However i have 12 columns in my label datasets. And my model works when there is only 1 label. How i can make it to train for all labels?
My model in the Train_val.prototxt is looking like this for now:
Any kind of help or suggestion will be highly appreciated.

If I understand you correctly, you are trying to predict 12 discrete labels (attributes) for each input example. In that case, you should "Slice" the labels:
layer {
type: "Slice"
name: "slice_labels"
bottom: "label"
top: "attr_00"
top: "attr_01"
top: "attr_02"
top: "attr_03"
top: "attr_04"
top: "attr_05"
top: "attr_06"
top: "attr_07"
top: "attr_08"
top: "attr_09"
top: "attr_10"
top: "attr_11"
slice_param {
axis: -1 # slice the last dimension
slice_point: 1
slice_point: 2
slice_point: 3
slice_point: 4
slice_point: 5
slice_point: 6
slice_point: 7
slice_point: 8
slice_point: 9
slice_point: 10
slice_point: 11
}
}
Now, you have a "scalar" label for each attribute. I believe you can take it from here.

Related

bmr calculator: use values from one class/scrren

I'm trying to use values from one class/scrren to multiply with another class screen but keep getting 0.
I know i probably do not carry the variable properly from one class to another but seem to have tried almost everything so if I dont get nontype error I just get 0 value when multiplying anything, like I would carry 0 from my second screen in the values which i have to input in the second screen. Any ideas? as Im brand new on kivy
.py
class SecondWindow(Screen):
ageInput = NumericProperty()
weightInput = NumericProperty()
heightInput = NumericProperty()
def info(self):
age = self.ids.ageInput.text
ageVal = int(age)
height = self.ids.heightInput.text
heightVal = int(height)
weight = self.ids.weightInput.text
weightVal = int(weight)
add = int(age) + int(height) - int(weight)
self.ids.label.text = str(add)
addVal = self.ids.label.text
print (addVal)
return ageVal, heightVal, weightVal
class ThirdWindow(Screen):
male = ObjectProperty()
female = ObjectProperty()
second = ObjectProperty()
def bmrCalc(self, button, weight):
choice = self.ids.lbl.text
if choice == "":
self.ids.lbl.text = button
self.weight = self.second.weightInput
if self.ids.lbl.text == "male":
m = 66.5
mw = 13.75 * int(self.second.weightInput)
mh = 5.003 * int(self.second.heightInput)
ma = 6.75 * int(self.second.ageInput)
print(mw)
.kv file
<SecondWindow>:
id: second
name: "second"
age: ageInput
hheight: heightInput
weight: weightInput
lbl1: label
FloatLayout:
canvas.before:
Color:
rgba: 255, 0, 0, 1
Rectangle:
# self here refers to the widget i.e FloatLay
pos: self.pos
size: self.size
Label:
text: "Calorie Intake Calculator"
font_size: 35
pos_hint: {"x": 0.3, "top": 1}
size_hint: 0.35, 0.1
Label:
text: "Enter your age"
font_size: 30
pos_hint: {"x": 0.1, "y": 0.8}
size_hint: 0.3, 0.1
TextInput:
id: ageInput
font_size: 15
multiline: False
pos_hint: {"x": 0.5 , "y":0.82}
size_hint:0.3, 0.05
Label:
text: "Enter your height(cm)"
font_size: 30
pos_hint: {"x": 0.1, "y": 0.6}
size_hint: 0.3, 0.1
TextInput:
id: heightInput
font_size: 15
multiline: False
pos_hint: {"x": 0.5 , "y":0.62}
size_hint:0.3, 0.05
Label:
text: "Enter your weight(kg)"
font_size: 30
pos_hint: {"x": 0.1, "y": 0.4}
size_hint: 0.3, 0.1
TextInput:
id: weightInput
font_size: 15
multiline: False
pos_hint: {"x": 0.5 , "y":0.42}
size_hint:0.3, 0.05
Button:
pos_hint: {"x":0.35, "y": 0.3}
size_hint: 0.3, 0.05
text: "Submit"
on_press:
root.info()
app.root.current = "third"
root.manager.transition.direction = "left"
Label:
id: label
text: "text"
font_size: 15
pos_hint: {"x": 0.7, "y": 0.1}
size_hint: 0.3, 0.2
Button:
pos_hint: {"x":0.35, "y": 0.15}
size_hint: 0.3, 0.05
text: "Back"
on_release:
app.root.current = "first"
root.manager.transition.direction = "right"
<ThirdWindow>:
id: third
name: "third"
lbl: lbl
male: male
female: female
FloatLayout:
canvas.before:
Color:
rgba: 153, 0, 0, 1
Rectangle:
# self here refers to the widget i.e FloatLayout
pos: self.pos
size: self.size
Label:
text: "Calorie Intake Calculator"
font_size: 35
pos_hint: {"x": 0.3, "top": 1}
size_hint: 0.35, 0.1
Label:
text: "Choose Your gender"
font_size: 30
pos_hint: {"x": 0.32, "top": 0.85}
size_hint: 0.35, 0.1
Button:
id: male
pos_hint: {"x":0.35, "y": 0.6}
size_hint: 0.3, 0.1
text: "Male"
on_press:
root.bmrCalc("male", "weight")
Button:
id: female
pos_hint: {"x":0.35, "y": 0.5}
size_hint: 0.3, 0.1
text: "Female"
on_press:
root.bmrCalc("female")
Label:
id: lbl
text: ""
font_size: 15
pos_hint: {"x": 0.35, "top": 0.3}
size_hint: 0.35, 0.1
Button:
pos_hint: {"x":0.35, "y": 0.1}
size_hint: 0.3, 0.05
text: "Back"
on_press:
app.root.current = "second"
root.manager.transition.direction = "right"

MDBoxLayout -> Widget width and height doesn't work ! kivy/kivymd

MDBoxLayout:
orientation: "vertical"
Widget:
size_hint_y: 5
height: 100
width: 100
canvas:
Color:
rgb: 1, 1, 1
Ellipse:
size: self.width / 3 , self.width / 3
pos: ( self.width - ( self.width / 3 ) ) / 2 , self.height - 100
source: 'cat-1.jpg'
angle_start: 0
angle_end: 360
ScrollView:
MDList:
id: scroll
OneLineAvatarIconListItem:
id: profile
text: "Profile"
elevation: 10
IconLeftWidget:
icon: "account-card-details-outline"

Highcharts gauge not showing colour as expected

I have 3 stops at 0.4, 0.6 and 0.8 (red, green, blue). The maximum is 100 (for percent)
If I set the data as 50, I expect it to be green but it seems to be a mix of the green and red. It's only when I get to 60 that it's bright green that I expect.
Anyway to remove the gradient?
https://jsfiddle.net/sy3r2hj7/1/
var gaugeOptions = {
chart: {
type: 'solidgauge'
},
title: null,
pane: {
center: ['50%', '85%'],
size: '140%',
startAngle: -90,
endAngle: 90,
background: {
backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || '#EEE',
innerRadius: '60%',
outerRadius: '100%',
shape: 'arc'
}
},
tooltip: {
enabled: false
},
// the value axis
yAxis: {
stops: [
[0.40, '#ff0000'],
[0.60, '#00ff00'], // yellow
[0.80, '#0000ff'] // red
],
lineWidth: 0,
minorTickInterval: null,
tickAmount: 2,
title: {
y: -70
},
labels: {
y: 16
}
},
plotOptions: {
solidgauge: {
dataLabels: {
y: 5,
borderWidth: 0,
useHTML: true
}
}
}
};
// The speed gauge
var chartSpeed = Highcharts.chart('container-speed', Highcharts.merge(gaugeOptions, {
yAxis: {
min: 0,
max: 100,
title: {
text: 'Speed'
}
},
credits: {
enabled: false
},
series: [{
name: 'Speed',
data: [60],
dataLabels: {
format: '<div style="text-align:center"><span style="font-size:25px;color:' +
((Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black') + '">{y}</span><br/>' +
'<span style="font-size:12px;color:silver">km/h</span></div>'
},
tooltip: {
valueSuffix: ' km/h'
}
}]
}));
Instead of using stops property, you can change the color of the point programmatically, based on some condition:
events: {
render: function() {
var point = this.series[0].points[0];
if (point.y < 40) {
point.graphic.attr({
fill: '#ff0000'
})
} else if (point.y < 60) {
point.graphic.attr({
fill: '#00ff00'
})
} else {
point.graphic.attr({
fill: '#0000ff'
})
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/fw594Lmg/

How to extract sprites out from Sprite Sheet in SpriteKit?

I wanted to extract each of the sprites in the following sprite sheet.
Provided with the key-value of sprite origin points in the sheet.
each sprite into its own SKSpriteNode object
I think through using SKTexture somehow
{
CACTUS_LARGE: { x: 652, y: 2 },
CACTUS_SMALL: { x: 446, y: 2 },
CLOUD: { x: 166, y: 2 },
HORIZON: { x: 2, y: 104 },
MOON: { x: 954, y: 2 },
PTERODACTYL: { x: 260, y: 2 },
RESTART: { x: 2, y: 2 },
TEXT_SPRITE: { x: 1294, y: 2 },
TREX: { x: 1678, y: 2 },
STAR: { x: 1276, y: 2 }
}

Use gradient color in Highchart solidgauge

$(function () {
var gaugeOptions = {
chart: {
type: 'solidgauge'
},
title: null,
pane: {
center: ['50%', '85%'],
size: '140%',
startAngle: -90,
endAngle: 90,
background: {
backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || '#EEE',
innerRadius: '60%',
outerRadius: '100%',
shape: 'arc'
}
},
tooltip: {
enabled: false
},
// the value axis
yAxis: {
lineWidth: 0,
minorTickInterval: null,
tickPixelInterval: 400,
tickWidth: 0,
title: {
y: -70
},
labels: {
y: 16
}
},
plotOptions: {
solidgauge: {
dataLabels: {
y: 5,
borderWidth: 0,
useHTML: true
}
}
}
};
// The speed gauge
$('#container-speed').highcharts(Highcharts.merge(gaugeOptions, {
yAxis: {
min: 0,
max: 100,
title: {
text: 'Speed'
}
},
series: [{
name: 'Speed',
data: [75]
}]
}));
});
Using the Highchart's solidgauge. Is there a way to have a gradient color up to the value showing on the gauge?
For example if my gauge is from 0 to 100, and at a specific time the value we are showing is 75, I want to show it as a gradient color transitioning from a green left section to small red right section. Of course the remaining 25% of the gauge in this example should not have any color just showing the background color of the gauge.
Is there a way to do that?

Resources