Skip to content

Instantly share code, notes, and snippets.

View nprasad2021's full-sized avatar

Neeraj Prasad nprasad2021

  • MIT
  • Cambridge, Massachusetts
View GitHub Profile
import sys
SCORES = [7, 15, 12, 44, 12]
OPTIONS = [2, 3, 3, 1, 5]
ISSUES = ["A", "B", "C", "D", "E"]
NAMES = {
"A": "Data Sharing",
"B": "Seeds and Capital",
"C": "Restrictions on Local Genetic Resources",
@nprasad2021
nprasad2021 / quality_prediction.py
Created January 9, 2020 05:18
model predictions for s1, n450, n530, n630
import numpy as np
import tensorflow as tf
from rdkit import Chem
from rdkit.Chem import AllChem
from tensorflow.keras.models import Sequential
from abc import ABC, abstractmethod
MODEL_PATHS = {
'n450': '/home/sandia/OLED_HTL_PRIME/CPL_ver/training/N2_750/models/n450.h5',
'n530': '/home/sandia/OLED_HTL_PRIME/CPL_ver/training/N2_750/models/n530.h5',

How to train and test the head detector

Neeraj Prasad

Setup and Installation

Run the following instructions in bash in your Linux Environment with GPUs

git clone git@gist.github.com:9c3d406f69580929fe86023154dd4390.git
mv 9c3d406f69580929fe86023154dd4390/head_detector.sh ./head_detector.sh
chmod +x head_detector.sh
@nprasad2021
nprasad2021 / head_detector.sh
Last active January 29, 2019 17:14
create a head detector in linux w/ cuda
#!/bin/bash
mkdir head_detector
cd head_detector
git clone git@github.com:nprasad2021/maskrcnn-benchmark.git
cd maskrcnn-benchmark
python3 -m venv ./mask
source ./mask/bin/activate
pip3 install ninja yacs cython matplotlib xmltodict future
pip3 install opencv-python==3.4.5.20 sklearn requests
pip3 install torch torchvision
with tf.Session() as sess:
	# Instantiate all variables
	sess.run(global_init)

	training_handle = sess.run(train_iterator.string_handle())
	validation_handle = sess.run(val_iterator.string_handle())


	num_epochs = 20
total_loss = tf.losses.get_total_loss()
global_step = tf.Variable(0, trainable=False)

params = tf.trainable_variables()
gradients = tf.gradients(total_loss, params)

optimizer = tf.train.AdamOptimizer(learning_rate=0.001)
updates = optimizer.apply_gradients(zip(gradients, params), global_step=global_step)
global_init = tf.variables_initializer(tf.global_variables())
logits = inference(left_input_im, right_input_im)
loss(logits, left_label, right_label)
train_dataset = combine_dataset(batch_size=128, image_size=224, same_prob=0.95, diff_prob=.001, train=True)
val_dataset = combine_dataset(batch_size=128, image_size=224, same_prob=0.95, diff_prob=.001, train=False)
handle = tf.placeholder(tf.string, shape=[])

iterator = tf.data.Iterator.from_string_handle(
            handle, train_dataset.output_types, train_dataset.output_shapes)

train_iterator = train_dataset.make_one_shot_iterator()
val_iterator = val_dataset.make_one_shot_iterator()
def loss(logits, left_label, right_label):
	label = tf.equal(left_label, right_label)
	label = tf.cast(label, tf.int32)

	cross_entropy_loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=logits, labels=label))
	tf.losses.add_loss(cross_entropy_loss)
def inference(left_input_image, right_input_image)
	'''
	left_input_image: 3D tensor input
	right_input_image: 3D tensor input
	label: 1 if images are from same category. 0 if not.
	'''
	with tf.variable_scope('feature_generator', reuse=tf.AUTO_REUSE) as sc:

 left_features = model(left_input_image)