def helloa(*args,**kargs):
lala = {"lala":"lalala"}
lala["caca"] = "cacaca"
lala.update(kargs)
return lala
helloa(caca="papa",dada="dada")
运行结果:
{'caca': 'papa', 'dada': 'dada', 'lala': 'lalala'}
from keras import backend as K
input = K.ones(shape=(1,3))
print(input)
cast_input = K.cast(input,dtype = "float64")
print(cast_input)
运行结果:
<tf.Variable 'Variable:0' shape=(1, 3) dtype=float32, numpy=array([[1., 1., 1.]], dtype=float32)>
tf.Tensor([[1. 1. 1.]], shape=(1, 3), dtype=float64)
grid = [10, 5, 1, 2]
print(grid[:-1])
print(grid[::-1])
print(grid[::-2])
运行结果:
[10, 5, 1]
[2, 1, 5, 10]
[2, 5]
import numpy as np
from keras import backend as K
boxes = []
boxes.append([[1,2,3,4],[5,6,7,8]])
print (boxes)
boxes.append([[1,2,3,4],[5,6,7,8]])
print (boxes)
boxes.append([[1,2,3,4],[5,6,7,8]])
print (boxes)
boxes = K.concatenate(boxes, axis=0)
print (boxes)
mask = boxes >= 4
print (mask)
max = K.constant(20)
print (max)
运行结果:
[[[1, 2, 3, 4], [5, 6, 7, 8]]]
[[[1, 2, 3, 4], [5, 6, 7, 8]], [[1, 2, 3, 4], [5, 6, 7, 8]]]
[[[1, 2, 3, 4], [5, 6, 7, 8]], [[1, 2, 3, 4], [5, 6, 7, 8]], [[1, 2, 3, 4], [5, 6, 7, 8]]]
tf.Tensor(
[[1 2 3 4]
[5 6 7 8]
[1 2 3 4]
[5 6 7 8]
[1 2 3 4]
[5 6 7 8]], shape=(6, 4), dtype=int32)
tf.Tensor(
[[False False False True]
[ True True True True]
[False False False True]
[ True True True True]
[False False False True]
[ True True True True]], shape=(6, 4), dtype=bool)
tf.Tensor(20.0, shape=(), dtype=float32)
import numpy as np
boxes_wh = [[[10,10],[0,0],[0,0]],[[20,20],[30,30],[0,0]]]
boxes_wh = np.array(boxes_wh)
valid_mask = boxes_wh[..., 0]>0
anchors = [[5,5],[10,10],[20,20],[30,30],[40,40]]
anchors = np.array(anchors)
anchors = np.expand_dims(anchors, 0)
anchor_maxes = anchors / 2.
anchor_mins = -anchor_maxes
for b in range(0,2):
wh = boxes_wh[b, valid_mask[b]]
wh = np.expand_dims(wh, -2)
box_maxes = wh / 2.
box_mins = -box_maxes
intersect_mins = np.maximum(box_mins, anchor_mins)
intersect_maxes = np.minimum(box_maxes, anchor_maxes)
intersect_wh = np.maximum(intersect_maxes - intersect_mins, 0.)
intersect_area = intersect_wh[..., 0] * intersect_wh[..., 1]
box_area = wh[..., 0] * wh[..., 1]
anchor_area = anchors[..., 0] * anchors[..., 1]
iou = intersect_area / (box_area + anchor_area - intersect_area)
best_anchor = np.argmax(iou, axis=-1)
anchor_mask = [[6,7,8], [3,4,5], [0,1,2]]
print(anchor_mask[0].index(7))
print(np.floor(3.1))
for t, n in enumerate(best_anchor):
print(t,n)
运行结果:
1
3.0
0 1
1
3.0
0 2
1 3
import tensorflow as tf
import keras.backend as K
true_boxes = [[[[1,2,3,4],[0,0,0,0],[5,6,7,8]],[[0,0,0,0],[1,1,1,1],[1,1,1,1]]],[[[1,2,3,4],[0,0,0,0],[0,0,0,0]],[[0,0,0,0],[0,0,0,0],[1,0,0,0]]]]
object_mask = [[[1,0,1],[0,1,1]],[[1,0,0],[0,0,1]]]
ignore_mask = tf.TensorArray("float32", size=1, dynamic_size=True)
object_mask_bool = K.cast(object_mask, 'bool')
true_box = tf.boolean_mask(true_boxes, object_mask_bool)
c=0
ignore_mask = ignore_mask.write(c, K.cast(0.5<0.6, "float32"))
print (ignore_mask)
print (true_box)
print (true_box[...,0])
print (ignore_mask)
for i in range(0,5):
ignore_mask.write(i,i)
print (ignore_mask.read(i))
print(ignore_mask.stack())
ignore_mask = ignore_mask.stack()
ignore_mask = K.expand_dims(ignore_mask, -1)
print (ignore_mask)
print (object_mask_bool)
运行结果:
<tensorflow.python.ops.tensor_array_ops.TensorArray object at 0x000002ADC79185C0>
tf.Tensor(
[[1 2 3 4]
[5 6 7 8]
[1 1 1 1]
[1 1 1 1]
[1 2 3 4]
[1 0 0 0]], shape=(6, 4), dtype=int32)
tf.Tensor([1 5 1 1 1 1], shape=(6,), dtype=int32)
<tensorflow.python.ops.tensor_array_ops.TensorArray object at 0x000002ADC79185C0>
tf.Tensor(0.0, shape=(), dtype=float32)
tf.Tensor(1.0, shape=(), dtype=float32)
tf.Tensor(2.0, shape=(), dtype=float32)
tf.Tensor(3.0, shape=(), dtype=float32)
tf.Tensor(4.0, shape=(), dtype=float32)
tf.Tensor([0. 0. 0. 0. 0.], shape=(5,), dtype=float32)
tf.Tensor(
[[0.]
[0.]
[0.]
[0.]
[0.]], shape=(5, 1), dtype=float32)
tf.Tensor(
[[[ True False True]
[False True True]]
[[ True False False]
[False False True]]], shape=(2, 2, 3), dtype=bool)
from keras.layers import Input, Lambda
image_input = Input(shape=(None, None, 3))
print(image_input)
运行结果;
Tensor("input_2:0", shape=(None, None, None, 3), dtype=float32)
import numpy as np
import tensorflow as tf
boxes = np.array([[1],[0],[2],[5],[3]])[:,0]
mask = np.array([[1],[0],[2],[5],[3]]) >= 3
print (boxes)
print(mask)
class_boxes = tf.boolean_mask(boxes, mask[:,0])
print (class_boxes)
运行结果:
[1 0 2 5 3]
[[False]
[False]
[False]
[ True]
[ True]]
tf.Tensor([5 3], shape=(2,), dtype=int32)
import tensorflow as tf
import math
depth_divisor = 8
min_depth = None
min_depth = min_depth or depth_divisor
print (min_depth)
运行结果:
8
filters = 32
multiplier = 1.2
filters = filters * multiplier
print (filters)
new_filters = max(min_depth, int(filters + depth_divisor / 2) // depth_divisor * depth_divisor)
if new_filters < 0.9 * filters:
new_filters += depth_divisor
print (filters + depth_divisor/2)
print (int(filters + depth_divisor/2)//depth_divisor)
print (new_filters)
运行结果:
38.4
42.4
5
40
repeats = 3
multiplier = None
if not multiplier:
print (repeats)
else:
print (int(math.ceil(multiplier * repeats)))
运行结果:
3