mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-13 11:57:29 +08:00
modified saliency function to accept more parameters
This commit is contained in:
parent
37c67f0f5d
commit
faf3b738f4
@ -174,8 +174,9 @@ class Webcam(AbstractInput):
|
||||
|
||||
|
||||
class Textbox(AbstractInput):
|
||||
def __init__(self, sample_inputs=None):
|
||||
def __init__(self, sample_inputs=None, preprocessing_fn=None):
|
||||
self.sample_inputs = sample_inputs
|
||||
super().__init__(preprocessing_fn=preprocessing_fn)
|
||||
|
||||
def get_validation_inputs(self):
|
||||
return validation_data.ENGLISH_TEXTS
|
||||
|
@ -126,6 +126,7 @@ def set_sample_data_in_config_file(temp_dir, sample_inputs):
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def set_disabled_in_config_file(temp_dir, disabled):
|
||||
config_file = os.path.join(temp_dir, CONFIG_FILE)
|
||||
render_template_with_tags(
|
||||
@ -184,13 +185,14 @@ def serve_files_in_background(interface, port, directory_to_serve=None):
|
||||
self._set_headers()
|
||||
data_string = self.rfile.read(int(self.headers["Content-Length"]))
|
||||
msg = json.loads(data_string)
|
||||
processed_input = interface.input_interface.preprocess(msg["data"])
|
||||
raw_input = msg["data"]
|
||||
processed_input = interface.input_interface.preprocess(raw_input)
|
||||
prediction = interface.predict(processed_input)
|
||||
processed_output = interface.output_interface.postprocess(prediction)
|
||||
output = {"action": "output", "data": processed_output}
|
||||
if interface.saliency is not None:
|
||||
import numpy as np
|
||||
saliency = interface.saliency(interface.model_obj, processed_input, prediction)
|
||||
saliency = interface.saliency(interface.model_obj, raw_input, processed_input, prediction, processed_output)
|
||||
output['saliency'] = saliency.tolist()
|
||||
|
||||
# Prepare return json dictionary.
|
||||
|
@ -1,31 +0,0 @@
|
||||
import tensorflow as tf
|
||||
import gradio
|
||||
|
||||
|
||||
#CREATE INTERFACE USING 'GOOD' MNIST MODEL
|
||||
(x_train, y_train),(x_test, y_test) = tf.keras.datasets.mnist.load_data()
|
||||
model = tf.keras.models.load_model('MNIST_9344.h5')
|
||||
input = gradio.inputs.Sketchpad(sample_inputs=x_train[:10])
|
||||
iface = gradio.Interface(inputs=input, outputs="label", model=model, model_type='keras')
|
||||
iface.launch(inline=False, share=False, inbrowser=True);
|
||||
|
||||
|
||||
#CREATE INTERFACE BY TRAINING MSNIST MODEL
|
||||
|
||||
# (x_train, y_train),(x_test, y_test) = tf.keras.datasets.mnist.load_data()
|
||||
# x_train, x_test = x_train / 255.0, x_test / 255.0
|
||||
#
|
||||
# model = tf.keras.models.Sequential([
|
||||
# tf.keras.layers.Flatten(),
|
||||
# tf.keras.layers.Dense(512, activation=tf.nn.relu),
|
||||
# tf.keras.layers.Dropout(0.2),
|
||||
# tf.keras.layers.Dense(10, activation=tf.nn.softmax)
|
||||
# ])
|
||||
#
|
||||
# model.compile(optimizer='adam',
|
||||
# loss='sparse_categorical_crossentropy',
|
||||
# metrics=['accuracy'])
|
||||
# model.fit(x_train, y_train, epochs=1)
|
||||
# inp = gradio.inputs.Sketchpad(sample_inputs=x_train[:10])
|
||||
# iface = gradio.Interface(inputs=inp, outputs="label", model=model, model_type='keras')
|
||||
# iface.launch(inline=False, share=False, inbrowser=True);
|
Loading…
x
Reference in New Issue
Block a user