voidfoo(){ EASY_FUNCTION(profiler::colors::Magenta); // Magenta block with name "foo"
EASY_BLOCK("Calculating sum"); // Begin block with default color == Amber100 int sum = 0; for (int i = 0; i < 10; ++i) { EASY_BLOCK("Addition", profiler::colors::Red); // Scoped red block (no EASY_END_BLOCK needed) sum += i; } EASY_END_BLOCK; // End of "Calculating sum" block
EASY_BLOCK("Calculating multiplication", profiler::colors::Blue500); // Blue block int mul = 1; for (int i = 1; i < 11; ++i) mul *= i; //EASY_END_BLOCK; // This is not needed because all blocks are ended on destructor when closing braces met }
voidbar(){ EASY_FUNCTION(0xfff080aa); // Function block with custom ARGB color }
voidbaz(){ EASY_FUNCTION(); // Function block with default color == Amber100 }
Matrix multiplication is where two matrices are multiplied directly. This operation multiplies matrix A of size [a x b] with matrix B of size [b x c] to produce matrix C of size [a x c].
In OpenCV it is achieved using the simple * operator:
C = A * B // Aab * Bbc = Cac
Element-wise multiplication is where each pixel in the output matrix is formed by multiplying that pixel in matrix A by its corresponding entry in matrix B. The input matrices should be the same size, and the output will be the same size as well. This is achieved using the mul() function:
for 2-dim, np.dot equals np.matmul for numpy.array, np.matmul means matrix multiplication; for numpy.matrix, * and np.matmul means matrix multiplication;
The default Jinja delimiters are configured as follows:
{% ... %} for Statements
{{ ... }} for Expressions to print to the template output
for Comments not included in the template output
# ... ## for Line Statements
{% set result_count = result_list | length %}
{{ index | string ) }}
filter: length, string
debug html
url_for with params
python code
1 2 3 4 5 6 7 8 9 10 11 12
@app.route('/index') @app.route('/') defindex(): return'you are in the index page'
@app.route('/questions/<int:question_id>'): #int has been used as a filter that only integer will be passed # in the url otherwise it will give a 404 error
deffind_question(question_id): return ('you asked for question {0}'.format(question_id))
@app.route("/") defindex(): # return the rendered template return render_template("index.html")
defgenerate(): # grab global references to the output frame and lock variables global outputFrame, lock
# loop over frames from the output stream whileTrue: # wait until the lock is acquired with lock: # check if the output frame is available, otherwise skip # the iteration of the loop if outputFrame isNone: continue
# encode the frame in JPEG format (flag, encodedImage) = cv2.imencode(".jpg", outputFrame)
# ensure the frame was successfully encoded ifnot flag: continue
# yield the output frame in the byte format yield(b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + bytearray(encodedImage) + b'\r\n')
@app.route("/video_feed") defvideo_feed(): # return the response generated along with the specific media # type (mime type) return Response(generate(), mimetype = "multipart/x-mixed-replace; boundary=frame") #===================================================
{% set result_count = result_list | length %} <h1>Search Results #{{result_count}}</h1> {% for i in range(0,result_count) %} {% set item = result_list[i] %} {% set segimg_filepath = item["segimg_filepath"] %} {% set segmask_filepath = item["segmask_filepath"] %}
{% set img_height = item["height"] %} {% set img_width = item["width"] %}
import keras import numpy as np from keras_radam import RAdam
# Build toy model with RAdam optimizer model = keras.models.Sequential() model.add(keras.layers.Dense(input_shape=(17,), units=3)) model.compile(RAdam(), loss='mse')
# Generate toy data x = np.random.standard_normal((4096 * 30, 17)) w = np.random.standard_normal((17, 3)) y = np.dot(x, w)
keras load model with custom optimizer with CustomObjectScope
error
when load model with custom optimizer, eg RAdam()
1
model = load_model("resnet50_radam_model.h5")
output error
ValueError: Unknown optimizer: RAdam
solution
1 2 3 4 5 6 7
from keras_radam import RAdam from keras.utils import CustomObjectScope
with CustomObjectScope({'RAdam': RAdam()}): best_model_filepath = "./checkpoint/best_model_efnb0.h5" model = load_model(best_model_filepath) model.save_weights("./checkpoint/weights_efnb0.h5")
compared with resnet50, EfficientNet-B4 improves the top-1 accuracy from 76.3% of ResNet-50 to 82.6% (+6.3%), under similar FLOPS constraint.
Using Pretrained EfficientNet Checkpoints
Keras Models Performance
The top-k errors were obtained using Keras Applications with the TensorFlow backend on the 2012 ILSVRC ImageNet validation set and may slightly differ from the original ones.
The input size used was 224x224 for all models except NASNetLarge (331x331), InceptionV3 (299x299), InceptionResNetV2 (299x299), Xception (299x299), EfficientNet-B0 (224x224), EfficientNet-B1 (240x240), EfficientNet-B2 (260x260), EfficientNet-B3 (300x300), EfficientNet-B4 (380x380), EfficientNet-B5 (456x456), EfficientNet-B6 (528x528), and EfficientNet-B7 (600x600).
notice
Top-1: single center crop, top-1 error
Top-5: single center crop, top-5 error
10-5: ten crops (1 center + 4 corners and those mirrored ones), top-5 error
Size: rounded the number of parameters when include_top=True
Stem: rounded the number of parameters when include_top=False
# import the necessary packages from keras.preprocessing.image import ImageDataGenerator from keras.preprocessing.image import img_to_array from keras.preprocessing.image import load_img import numpy as np import argparse
from keras_util import *
# construct the argument parse and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", required=True, help="path to the input image") ap.add_argument("-o", "--output", required=True, help="path to output directory to store augmentation examples") ap.add_argument("-p", "--prefix", type=str, default="image", help="output filename prefix") args = vars(ap.parse_args())
# load the input image, convert it to a NumPy array, and then # reshape it to have an extra dimension print("[INFO] loading example image...") target_size = None #target_size=(224,224) image = load_img(args["image"], target_size=target_size) image = img_to_array(image) image = np.expand_dims(image, axis=0) # 1,h,w,c
# construct the image generator for data augmentation then # initialize the total number of images generated thus far
# preprocessing_function: The function will run after the image is resized and augmented. # The function should take one argument: # one image (Numpy tensor with rank 3), # and should output a Numpy tensor with the same shape.
# for 1 image --->(424,640,3)--->aug---(424,640,3)--->preprocess_input--->(424,640,3) # for 1 image --->resize--->(224,224,3)--->aug---(224,224,3)--->preprocess_input--->(224,224,3) aug = ImageDataGenerator(preprocessing_function=resnet.preprocess_input, rotation_range=30, width_shift_range=0.1, height_shift_range=0.1, shear_range=0.2, zoom_range=0.2, horizontal_flip=True, fill_mode="nearest") total = 0
# construct the actual Python generator print("[INFO] generating images...") imageGen = aug.flow(image, batch_size=1, save_to_dir=args["output"], save_prefix=args["prefix"], save_format="png")