-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tobis.py
65 lines (45 loc) · 2.17 KB
/
Tobis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#! /usr/bin/env python
import tensorflow as tf
import keras.backend as K
from keras.applications.mobilenet import MobileNet
from keras.models import Model
from keras.layers import Reshape, Activation, Conv2D, Input, MaxPooling2D, BatchNormalization, Flatten, Dense, Lambda
from keras.optimizers import SGD, Adam, RMSprop
import numpy as np
from keras.utils import plot_model
#import keras
#def get_trainable_params(model):
# params = []
# for layer in model.layers:
# params += keras.engine.training.collect_trainable_weights(layer)
# return params
run_meta = tf.RunMetadata()
input_size= 416
max_box_per_image = 10
with tf.Session(graph=tf.Graph()) as sess:
K.set_session(sess)
input_image = Input(shape=(input_size, input_size, 3),name="input1")
true_boxes = Input(shape=(1, 1, 1, max_box_per_image , 4))
mobilenet = MobileNet(input_tensor=tf.placeholder('float32',shape=(1,input_size,input_size,3)),include_top=False,input_shape=(input_size,input_size,3),weights=None)(input_image)
detect = Conv2D(30,(1,1),strides=(1,1),padding='same',name='DetectoinLayer0')(mobilenet)
detect = Reshape((13, 13, 5, 6))(detect)
detect = Lambda(lambda args: args[0])([detect, true_boxes])
yolo = Model([input_image,true_boxes],detect)
plot_model(yolo, to_file='yolo.png')
print(detect)
yolo.summary()
optimizer = Adam(lr=1e-4, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)
yolo.compile(loss='mean_squared_error', optimizer=optimizer)
#yolo_params = get_trainable_params(yolo)
#param_grad = tf.gradients(detect, yolo_params)
#set up the train data
#X=np.random.rand(input_size,input_size,3)
#yolo.fit(x=X,steps_per_epoch=1)
#model.fit(steps_per_epoch=1)
#mobilenet.evaluate(x=X)
#Profiling ...
opts = tf.profiler.ProfileOptionBuilder.float_operation()
flops = tf.profiler.profile(sess.graph, run_meta=run_meta, cmd='scope', options=opts)
opts = tf.profiler.ProfileOptionBuilder.trainable_variables_parameter()
params = tf.profiler.profile(sess.graph, run_meta=run_meta, cmd='scope', options=opts)
print("{:,} --- {:,}".format(flops.total_float_ops, params.total_parameters))