Peter Naur's classic 1985 essay "Programming as Theory Building" argues that a program is not its source code. A program is a shared mental construct (he uses the word theory) that lives in the minds of the people who work on it. If you lose the people, you lose the program. The code is merely a written representation of the program, and it's lossy, so you can't reconstruct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_classification(self, img): | |
# Bounding Box Detection. | |
with self.detection_graph.as_default(): | |
# Expand dimension since the model expects image to have shape [1, None, None, 3]. | |
img_expanded = np.expand_dims(img, axis=0) | |
(boxes, scores, classes, num) = self.sess.run( | |
[self.d_boxes, self.d_scores, self.d_classes, self.num_d], | |
feed_dict={self.image_tensor: img_expanded}) | |
return boxes, scores, classes, num |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TrafficLightClassifier(object): | |
def __init__(self): | |
PATH_TO_MODEL = 'frozen_inference_graph.pb' | |
self.detection_graph = tf.Graph() | |
with self.detection_graph.as_default(): | |
od_graph_def = tf.GraphDef() | |
# Works up to here. | |
with tf.gfile.GFile(PATH_TO_MODEL, 'rb') as fid: | |
serialized_graph = fid.read() | |
od_graph_def.ParseFromString(serialized_graph) |
Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.
- Follow standard conventions.
- Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
- Boy scout rule. Leave the campground cleaner than you found it.
- Always find root cause. Always look for the root cause of a problem.